Hi All,
Yesterday I learnt how to turn off a layer through camera culling. However what I really want to do is pause the layer.
I’m actually loading multiple mini games onto levels to allow instant switch of games, no load of scene except at start. So on switch I pause and cull that level, then turn on objects and un-cull another layer.
My question is what’s the best way to turn the mini game, layer on?
1 is there a unity function for this?
2 do I need to use some loop to set all objects active i/ nactive via level name?
3 some better way?
You can just use SetActive(false) on a parent, and all child objects will be deactivated. If each game has a different parent, you can turn off/on the parent objects. MonoBehaviours have OnEnable() and OnDisable() which can be helpful in this case.
However, I find that this might not exactly work for more complicated games. I might have each game parent implement Suspend() and Resume() functions which would properly pause/restart each game. The parent would have to track children that need to be suspended properly and make sure that Suspend() is run on those children. Mobile games might even take the time to write game data to disk on Suspend() in case the app is terminated, in which case we can read the state of the game from disk and bring the player back to where they were on app load.