一:
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