1、添加自带物体
GameObject newHeadObj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
newHeadObj.transform.position = new Vector3(3,0,5);
Instantiate(newHeadObj);
2、添加预制体(预制体需要放在Assets/Resources目录下)
Transform parent; //父物体
GameObject item = Resources.Load<GameObject>("Button"); //根目录
GameObject prefab = Resources.Load<GameObject>("Prefabs/UI/PlayVideoUI");//Resources下路径
Instantiate(item, parent);//将预制体添加到父物体下
网友评论