- Home /
Lots of buttons with Game Manager. Need help with design.
Basically, I've got more scenes and I pass 4 objects between scenes using DontDestroyOnLoad
, one of them having a reference of my GameManager class (the object is game_manager). Some scenes have a lot of buttons that need to call functions defined in GameManager. As I can not use game_manager in another scene, I don't know how to assign these functions except at runtime writing for every scene a different SceneInitializer class. How can I organize my game management so that it is convenient?
Answer by StevenUnu · Sep 01, 2018 at 07:01 PM
I found a solution that's kind of convenient. If you have something better, don't hesitate to answer. So, I made all my class members static exept for Start, Awake and Update. I kept my signleton pattern and I assigned values using GameObject.Find
in Awake
. I created a static constructor with this code
static GameManager() {
SceneManager.activeSceneChanged += onSceneChange;
}
I defined a function onSceneChanged
which checks which scene was loaded and initializes the corresponding buttons.
Your answer
Follow this Question
Related Questions
Instantiating a Coroutine? 2 Answers
Unity 5 Network Manager subgames 0 Answers
How to manage different versions for different platforms? 0 Answers
What are the prerequisites to learn unity? 2 Answers
How to teleport to different scenes? 2 Answers