【发布时间】:2021-01-04 08:09:50
【问题描述】:
当我尝试向实例化的游戏对象添加预制件时,我收到错误消息:
禁止设置驻留在预制件中的转换的父级以防止数据损坏
当我第一次调用这个脚本时,一切正常。有很多类似的问题和答案。但是,我无法解决我的问题。
感谢您的帮助:)
GameObject coralWoodBundle = Resources.Load("Base/coral_wood_bundle") as GameObject;
GameObject woodlBundle = Instantiate(coralWoodBundle) as GameObject;
woodlBundle.transform.SetParent(this.gameObject.transform);
相关脚本
public class FallingWoodPackScript: MonoBehaviour
{
public List<FallingWoodScript> fallingWoodScripts;
public void Start()
{
RefillWood();
}
public void RefillWood()
{
GameObject coralWoodBundle = Resources.Load("Base/coral_wood_bundle") as GameObject;
GameObject woodlBundle = Instantiate(coralWoodBundle) as GameObject;
woodlBundle.transform.SetParent(this.gameObject.transform);
woodlBundle.transform.localPosition = new Vector3(1f, 2.7f, 0);
woodlBundle.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, -90));
fallingWoodScripts = new List<FallingWoodScript>();
foreach (Transform child in woodlBundle.transform)
{
fallingWoodScripts.Add(child.GetComponent<FallingWoodScript>());
}
}
}
【问题讨论】:
-
你能发布整个脚本吗?
-
我用脚本更新了描述。
-
您正在使用的游戏对象是实例化的还是一直存在(甚至在运行模式之前)?
-
它也是一个在播放模式下实例化的预制件。
标签: c# unity3d instantiation gameobject