How can someone create an instance at the beginning of a game? … what I am doing now is basicly this
public static class MyClass
{
static private MyClassCleaner = (new GameObject "MyClassCleaner")).AddComponent< MyClassCleaner> ();
static public Cleanup()
{
//Cleanup code
}
}
public MyClassCleaner : MonoBehavior
{
void Awake()
{
DontDestroyOnLoad(gameObject);
}
public void OnDisable()
{
MyClass.Cleanup();
}
}
But this doesn’t create the GameObject. I wanted the code above to create a persistent gameobject that cleans up my MyClass static class at the beginning of each level.
Is there a way to create a GameObject at the beginning of the game?
Is there a way to do this using static methods or by coding or is the only way creating a game object and attaching the MyClassCleaner script to it?