- Home /
Creating instance at the beginning of the game
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?
Answer by getyour411 · Jan 25, 2014 at 02:19 AM
I think you could use ScriptableObject
http://docs.unity3d.com/Documentation/ScriptReference/ScriptableObject.html
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
C# Going Static or Going OOP 3 Answers
Can't Encode MD5 2 Answers
[C#] Is there a way to call static variables directly, independent from parent class? 3 Answers