I'm a beginner developing games on Unity3D and now that I've become a little bit familiar with GameManagers
I've been wondering about certain aspects.
How do you contruct a GameManager
in the most efficient way? Since it's an entity that persists through scene loads, it has to be tweaked to reset some values on level load because it doesn't do that by itself.
I'm making a 2D platformer, so when a new level is loaded (or the current level is restarted) the GameManager
has to dynamically find references to the objects it handles. And because each level cannot be identical to the next, should I have code in the GameManager
to find references to the specific GameObjects
and values depending on the level? I'm thinking something like this:
public class GameManager : MonoBehaviour {
//Values and core methods etc
void OnLevelWasLoaded(int level) {
if (level == 1) {
//Find references and set values for level 1
}
if (level == 2) {
//Find references and set values for level 2
}
}
}
Or should I have a separate GameManager
for values, game states and events and an in-between script for handling the GameObject
references? I just want to learn this right. I'm worrying that if I dump "everything" in the GameManager
, it becomes too big and inefficient.
Speaking of which, is it OK for the GameManager
to also handle the UI/HUD? Or should there be a separate UIManager
dedicated for this task?