What's the best way to setup a UI/Gamestate system in Unity?

So from as far as I can tell there seems to be 3 ways to setup a UI system that is based off the Gamestate changes and they are:

  1. Load a new scene for each Gamestate change which has the new UI.

  2. Load a prefab of the UI for the Gamestate change.

  3. Have all the UI gameobjects scenes in the start scene with DontDestroyOnLoad, and then active/deactivate them as the Gamestate changes.

I was wondering if anyone could offer any feedback or advice on which implementations they’ve done in their games, and which seems to be the best for mobile?

What is “GameState”?

By GameStates I mean the states of a game, so that the entire game is setup as a state machine.

Thus, one Gamestate would be main menu, another Gamestate would be pause menu, and another the gameplay state, etc…

Oh, I see. Well I usually separate everything into scenes. So I have a Main Menu, Options, Game, Game Over, all in separate scenes of their own. And each scene has their own UI and are not linked in any way to the other scenes UI. So that would be option #1 I think.

Anyone else care to give me their thoughts or comments? Maybe I should setup a poll.

We usually give each menu its own prefab. We have a GUI/HUD Manager sitting in the scene that decide which menu should be shown. That GUI/HUD Manager picks a menu prefab, instantiates it, and displays it.

The GUI/HUD Manager can also close the menu, destroy it, then switch to a different menu prefab if needed.

I’m fairly new to Unity, but I’ve gone down the GameState manager route for my game, with each menu as a script. To display the menu I add the script component to a gameobject in the scene.

The menuscript when it loads, caches the current gameState, and then sets the gameState to its particular value (the menu will only display when gameState is set to the value it is expecting). When the menu is closed it resets the gameState to the cached value and then destroys itself.

I hope you can make some sense of the above, I went through lots of methods that didn’t work reliably before I hit on this one, and so far this does the job, although I’ve no doubt there are many other ways to approach it.

I’ve used it in the game that I’ve linked in my signature if you want to see it working.