- Home /
DontDestroyOnLoad Missing Object
void Awake() { alpha.DontDestroyOnLoad(alpha); gama.DontDestroyOnLoad(gama); betha.DontDestroyOnLoad(betha); duo.DontDestroyOnLoad(duo); }
Here is my code.
Unity is giving missing object error after i used Application.LoadLevel(0)
What might be the problem?
Thanks for help :)
Answer by Ashish Dwivedi · Feb 15, 2014 at 04:09 PM
Call DontDestroyOnLoad(alpha) instead "alpha.DontDestroyOnLoad(alpha)". Make sure that the object you are passing as argument must not be null.
void Awake() { DontDestroyOnLoad(alpha); DontDestroyOnLoad(gama); DontDestroyOnLoad(betha); DontDestroyOnLoad(duo); }
I tried this also but still getting this error:
$$anonymous$$issingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
void Awake() { DontDestroyOnLoad(alpha); DontDestroyOnLoad(gama); DontDestroyOnLoad(betha); DontDestroyOnLoad(duo); }
$$anonymous$$issingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
It is still giving this error i dont get it ? How can i solve this problem ?
Here is the whole script.
public GameObject alpha, newAlpha; public GameObject player; public bool forAlpha = true; public bool run = false, destroyButton = true; float time;
void Start () { time = Time.time; }
void Update () { if(player != null){ obstacles (); } }
void Awake() { DontDestroyOnLoad(alpha); }
void OnGUI(){ if(destroyButton){ if(GUI.Button(new Rect(300,250,100,100),"Play")){ run = true; destroyButton = false; } } if (adam == null) { if(GUI.Button(new Rect(300,250,100,100),"Try Again")){ run = true; Application.LoadLevel(0); } } }
void spawnAlpha() { float Co_x = Random.Range (-7, 8); newAlpha = (GameObject) Instantiate(alpha, new Vector3(Co_x,20,0), Quaternion.identity); forAlpha = false; }
void obstacles(){ if(forAlpha){ if(time % 3 == 0) spawnAlpha (); } newAlpha.transform.Translate (0,-0.1f,0); if (newAlpha.transform.position.y < 0) { Destroy (newAlpha); forAlpha = true; } }