1. 程式人生 > >Unity例項化Prefab到指定位置

Unity例項化Prefab到指定位置

1.定義public型別的預製體,並在場景中將要例項化的預製體拖到指令碼下

2.定義需要例項化的位置,是一個Vector3型別的變數;

3.定義需要例項化的旋轉角度,是一個四元數;

public GameObject shellPrefab;

public Vector3 a = Vector3.zero;
public Quaternion b = new Quaternion(0,0,0,0);

GameObject go = GameObject.Instantiate(shellPrefab,a,b) as GameObject;