[英]Instantiate a gameobject as Child
我正在使用Unity开发2D UI应用程序,但遇到了问题。 我正在使用脚本实例化我的弹出窗口(我做了一个预制件)。 我成功了,但是后来Unity崩溃了,我不得不重做我的场景(忘记按ctrl + s)。自从这次崩溃以来,我的弹出窗口并没有实例化为我的画布的孩子,并且我得到了以下消息:“设置父对象禁用了预制中的转换,以防止数据损坏”
这是我的脚本:
using UnityEngine;
using System.Collections;
public class Popup : MonoBehaviour
{
public RectTransform popupPrefab;
private Animator anim;
// Use this for initialization
void Start()
{
//get the animator component
anim = popupPrefab.GetComponent<Animator>();
//disable it on start to stop it from playing the default animation
anim.enabled = false;
}
public void CreatePopup()
{
// Copie du prefab
RectTransform newPopup = Instantiate(popupPrefab, popupPrefab.transform.position, popupPrefab.transform.rotation) as RectTransform;
newPopup.transform.SetParent(transform, false);
//anim = newPopup.GetComponent<Animator>();
//anim.enabled = true;
//anim.Play("Popup");
}
public void ClosePopup()
{
anim.enabled = true;
anim.Play("ClosePopup");
}
}
我不明白为什么我会遇到这个错误,因为它在崩溃前工作正常...
如果您有任何想法,谢谢
我从一开始就通过重新做项目来解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.