- Home /
what objects can I make static
Hi all, I have a couple of objects that basically won't change (won't get destroyed, or altered) during game play. These objects are for example - AudioManager, GameControler, PlayersClonesContainer, and so on. Is it a good idea to make them static?
-----------edited------------ Each of this objects has it's own script attached, eg. AudioManager_scr, GameControler_scr, etc. Can I make variables contained within those scripts static? Provided they won't change during the game. Come to think of it...shouldn't I make them constants?
@Itaros Yes, I'm sorry I didn't formulate my question correctly. I meant variables that hold references to these objects. Btw I've just "thumbed-up" your question :)
Answer by Landern · Oct 25, 2014 at 03:08 PM
Generally Managers are full objects that are implemented through a singleton pattern, because of how unity works, the singleton pattern needs to be modified to use unity's state machine methods such as Awake, Start, etc.
Unify Community has a couple entries you may want to look at:
The singleton pattern allows you to setup static classes that inherit from MonoBehaviour that can be attached to GameObjects and use the same instance of that class. These objects can be marked with DontDestroyOnLoad to ensure they transcend scenes and retain their various values/properties/etc.
Your answer
Follow this Question
Related Questions
My car object moves on its own ANY FIX?? PLEASE 1 Answer
AddComponent deletes the game object. 1 Answer
How to control Another Object by using other one 1 Answer
Sending data to different game objects? 1 Answer
Smooth enter orbit 2 Answers