hello dear developers
i have class called variables. When I use it in my collectmoney class i must attach variables class to a empty gameobject order to work(and I have to create get component to collectmoney class). But WHY cant we just simple not attach it(variables class) to a gameobject and only attach colllecmoney script to a coin(or money)(Coin is a gameobject like cube ) and simply works ? Must I attach EVERY script to a gameobject ?
You could simply remove MonoBehaviour from your variables class declaration. Then, to use it, write public Variables vars;, and you should be ready to go.
EDIT:
But, always remember: if it doesn’t work, write: public Variables vars = new Variables();
Try setting the variables class to static, then you should be able to reference it without an object reference.