- Home /
Component or Independent class
Greetings,
I started to play quite seriously with Unity and red a couple of articles in the doc, forum posts and book chapters. I understand the GameObject / Components way of doing things, but I am still a bit uncomfortable about when to create an empty GameObject with some component attached to it or construct an independant class to be used by another object.
Here is an exemple, I created an empty GameManager object and attached a GameManager component script to it. However, the only script to be ever attached to this GameObject is the GameManager component. I understand that it is possible to access GameObjects from almost anywere in the code, but it seems more like bad programming to me.
I'm I right ? Should I use classes or GameObjects for managers and such ?
Thanks for your answers !
Answer by flaviusxvii · Jun 09, 2011 at 07:00 PM
A "class" is an intangible abstract thing. It's a blueprint for an actual thing.
You can use a Component attached to an empty GameObject (which I prefer, cause you can inspect it and it's nicer for lots of things)
Or you can use a singleton class instance. That's an 'actual' instance of a class, but you just keep one global one around.
Take your pick.
Yeah I know about singleton pretty well, but what should I choose between Singleton and GameObject and why ? Thanks for your reply by the way !