> Code
더보기
> App.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class App : MonoBehaviour
{
public Button btn;
public GameObject heroPrefab;
public GameObject weaponPrefab;
private void Start()
{
this.btn.onClick.AddListener(() => {
var heroModelGo = this.CreateModel();
var weaponGo = this.CreateWeapon();
var dummyRHand = heroModelGo.GetComponent<HeroModel>().dummyRHand;
weaponGo.transform.SetParent(dummyRHand, false);
});
}
private GameObject CreateModel()
{
return Instantiate(this.heroPrefab);
}
private GameObject CreateWeapon()
{
return Instantiate(this.weaponPrefab);
}
}
>HeroModel.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HeroModel : MonoBehaviour
{
public Transform dummyRHand;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
'c# 강의 > 유니티' 카테고리의 다른 글
20200511 - FindWithTag (자주 쓰이는 예제 필요) (0) | 2020.05.11 |
---|---|
20200508 - 프리팹 (0) | 2020.05.08 |
20200508 - 벡터1 (0) | 2020.05.08 |
20200508 - 복습 (0) | 2020.05.08 |
20200507 - 오브젝트 생성 및 부모설정(Instantiate) (0) | 2020.05.08 |