missing reference exception random maze generator
im getting a null reference exception when ever i destroy my gameobject then respawn it. i have a random maze generator which i made from a tutorial and made a few alteration to it the first being that it can increase it size and the second is that i can make alteration in the game manager rather then going directly to the maze prefab which is later instantiated in and destroy when i reset the maze.
using UnityEngine; using System.Collections;
public class GameManager : MonoBehaviour {
public Maze mazePrefab;
private Maze mazeInstance;
public IntVector2 sizeGM;
public GameObject mazeGO;
public Maze script;
private float
mazeScale;
public float
scaleUp = 5f;
void Start () {
StartCoroutine(BeginGame ());
}
void OnDestroy(){
StopAllCoroutines ();
}
private IEnumerator BeginGame(){
while(true){
mazeInstance = Instantiate (mazePrefab) as Maze;
mazeGO = GameObject.FindGameObjectWithTag ("MazeSetup");
script = mazeGO.GetComponent ("Maze") as Maze;
script.size = (sizeGM);
StartCoroutine (mazeInstance.Generate ());
while (!Input.GetKeyDown (KeyCode.Space) && !mazeInstance.IsFinished()) {
yield return null;
}
Debug.Log ("startScale");
Vector3 mazeScale = mazeGO.transform.localScale;
mazeScale.x += scaleUp;
mazeScale.y += scaleUp;
mazeScale.z += scaleUp;
mazeGO.transform.localScale = mazeScale;
Debug.Log ("finishScale");
Destroy (mazeInstance.gameObject);
}
}
}
it also destroy and recreate the maze endlessly but doesnt scale the maze up
Your answer
![](https://koobas.hobune.stream/wayback/20220612064748im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
MissingReferenceException when using StartCoroutine() after reloading a scene 2 Answers
Using a DLL to acess BTLE inside Unity 0 Answers
Destroying GameObject while in Inspector = MissingReferenceException 0 Answers
Unity_5.6.1f1 >> Unity_5.5.0f3 - Animation problems (missing reference)... 0 Answers