After that if the option button from the pause menu is pressed is opening the option menu, and here comes the actual problem is: if the back button when the level is open to get the player back to the pause menu, if the level is not opened to get the player back to the main menu, the code looks like this:
Input action pause is just the escape key ( can also be the back arrow for you ). See I can tell depending on which menu is in the variable, whether I need to reload the main menu, or exit the menu system…
Have a variable which is a reference to the menu you want to load.
When the player first presses ESC, this variable will be empty, then you know to load the main menu ( set the reference to the main menu also ).
If you’re in the main menu and they press ESC, you can tell from the variable the menu is loaded. Unload the menu and clear the variable.
When you go to a sub menu, you set the reference to the submenu. That way, when they press escape again ( or back arrow ), because the variable isn’t the main menu, you know to unload the sub menu, and re-load the main menu.
Does it make sense?..
You can of course do it with bools, but then you need to have bools AND menus flying around…
( Tell me what you want and I will either do a clearer example like this, or with bools )