GUI update to travel in menu

Hello,

I hope you can help me with this question, I have already looked into the database of questions but I havenn´t found anything.

My problem is that I need to create some sort of menu with at least 10 buttons in each menu (maybe more o less), then if I press any button it will take me to other menu that may look different that the GUI presented before, so I looking to a way of updating the GUI several times with the buttons, also the different GUI screens have to be connected because sometimes I need to come back to a GUI screen presented before. What would be the best way to enable the different configurations of the screens in the GUI???.

Each screen will have text, buttons and images or any combination of those. I was thinking something like a function that have all the information of how to update the GUI with a word o number that will identify that screen, but I am not familiarized with the code, I am working with JAVA scripts.

Please help.

There are several ways of doing this that I can think of. The basic idea is you have one GameObject/script that holds the current state and controls switching to other states. Then you define the states (in one of several ways) and controls that will transition between them.

Fast but messy:

In the state controller object, make a bunch of constants or an enum denoting all your states, and a variable holding the current state. Then in OnGUI(), have a switch..case statement with a case for each possible state. Then, if you want to switch states, just change the current state variable to whatever state you want and it will be displayed.

More time-consuming but more civilized:

Make a bunch of GameObjects/Prefabs, one for each state, and attach GUI scripts to them. Use your state controller object to instantiate and destroy the prefabs as needed. This has the advantage of being able to have several GUIs active at the same time (assuming they don’t overlap) and does not result in over 9000 lines of messy code in one script.

In either case, you want to have some form of switchState() function that you can call something like this:

if(Button(new Rect(0,0,100,100),"Go to state 1"))
    StateController.switchState(StateController.STATE_1);

This function can do anything from setting an int (as in the first example) to spawning/despawning a bunch of objects (as in the second example).