2016-03-07 96 views
1

我正在使用Unity處理2D UI應用程序,並且遇到問題。 我正在處理腳本來實例化我的彈出窗口(我做了一個預製)。我成功了,但後來團結崩潰,我不得不重做我的場景(忘了ctrl + s) 因爲這次崩潰,我彈出窗口不是實例化作爲我的畫布的孩子,我有這樣的消息: 「Setting the的變換是存在於預製父被禁用,以防止數據損壞」將一個遊戲對象實例化爲兒童

這裏是我的腳本:

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"); 
    } 
} 

我不明白爲什麼我有這樣的錯誤,因爲它是飛機墜毀前工作的罰款。如果您有任何想法,請致電

+0

是對不起它與UI對象 創建用帆布和UI工具的完整的UI界面 –

+0

這是我的實際代碼 什麼你的意思是 ? –

+0

嗨@danegirard。請選擇一個答案,以幫助保持董事會整潔。 – Fattie

回答

0

我通過重新做我的項目從一開始就解決了這個問題...

相關問題