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?
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.