오브젝트를 동적 생성할때 부모의 위치 설정하기.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class Test : MonoBehaviour {
    public GameObject _gameObjectPrefanb;
    public Transform _position;
    
    // 1번째
    public void Test1()
    {
        var Object = Instantiate(_gameObjectPrefanb);
        Object.transform.parent = _position.transform;
        Object.transform.localPosition = Vector3.zero;
        Object.transform.localScale = Vector3.one;
    }
    // 2번째 방법
    public void Test2()
    {
        var Object = Instantiate(_gameObjectPrefanb);
        Object.transform.SetParent(_position.transform);
    }
}
cs
끝.

댓글