Unity3D例項化物體
阿新 • • 發佈:2019-02-03
一:
public GameObject itemPrefab;
void Store()
{
if (transform.childCount == 0)
{
GameObject itemGameObject = Instantiate(itemPrefab) as GameObject;
itemGameObject.transform.SetParent(this.transform);
itemGameObject.transform.localScale = Vector3.one;
itemGameObject.transform.localPosition = Vector3.zero;
}
}
二:
public GameObject itemPrefab;
void Instantiate()
{
GameObject. Instantiate(itemPrefab,transform.position,Quaternion.identity);
//引數:例項化的目標,例項化的位置,每旋轉前的初始角度(Quaternion為四元數),實際為(0,0,0,0)
//也可以用transform.rotation,不過這個為父物體的旋轉角度,會將父物體的旋轉角度複製給例項化的物體
}
https://www.jianshu.com/p/7b4a53d24557