Deleting Debug Controllers On Loading Level

Hi All

There may be a better way, but when loading a level I want to delete the debug controller I use on that level to explore it and look at the art work etc...

I did have the following:

Application.LoadLevel("some_level_name");
GameObject controller = GameObject.Find("DebugController");
Destroy(controller);

However, it seems that DebugController cannot be find immediately after loading a level, so I wonder if there is a better way to do this?

Thanks Ian

This is most likely because it hasn't been instantiated yet. But an object can destroy itself, so you could do something like this inside of your DebugController's Awake() method:

if(!Application.isEditor)//if we aren't running in the editor
{
    GameObject.Destroy(gameObject);
}

Awake is called right after instantiation of the object, so this will kill it off almost immediately.

Cheers

==