I'm working on a 2D UI application with Unity and i have a problem. I was working on the script to instantiate my popup window (i made a prefab). And i succeed but later Unity crashed and i had to redo my scene (forgot to ctrl+s) Since this crash, my popup isn't instantiate as a child of my canvas and i've got this message: "Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption"
Here is my script :
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");
}
}
I don't understand why i have this error since it was working fine before crash...
if you have any idea Thanks