Question by
jni97 · Jan 27, 2016 at 05:06 PM ·
instanceclass instancenon-monobehavior
Non Monobehaviour GameManager?
Hi,
most time I use Monobehaviour scripts, but now I want to create a GameManager which contains a lot of variables. I don't want to attach it to a GameObject, that means I can't use monobehaviour. The variables have to be accessed from every script in my project and the variables are changed at runtime, so I can't use GameManager g = new GameManager();
How can I create and get one instance of a non-monobehaviour script?
Thanks for your help!
Comment
Best Answer
Answer by brunocoimbra · Jan 27, 2016 at 06:20 PM
You can try something like that:
// A static class can't me instantiated;
public static class GameManager
{
// Variables that can be acessed by GameManager.myVarName;
public static int myInt;
public static Vector2 myVector2;
// Methods that can be acessed by GameManager.myMethodName;
public static void MyMethod()
{
// do stuff;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612061947im_/https://answers.unity.com/themes/thub/images/avi.jpg)