Search Unity

Can I make a back button in unity?

Discussion in 'UGUI & TextMesh Pro' started by preety006, Jan 28, 2023.

  1. preety006

    preety006

    Joined:
    Jan 14, 2023
    Posts:
    1
    Hello all,

    I want to make a back pressed like button we make in Android studio to make it in Unity. Suppose we have 3 UI panels HomePanel, LobbyPanel and GamePanel.

    When i press the back button i can go back to my LobbyPanel, and same thing happens if i press the back button on Lobby. And when i press back button again on home, it won't go back instead the game will close. So is there any way to implement this using navigation stack in Unity and if there is i would like to know how we can implement this.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,956
    Take a look at my Netcode project, I implemented a very basic wizard menu with "back" navigation: https://github.com/CodeSmile-0000011110110111/UnityNetcodeBiteSizeExamples

    It's a very common misconception in Unity that every UI screen needs to be its own scene. This setup quickly leads to various issues and is quite inflexible. Instead you would have a manager script that handles enabling/disabling the UI objects for each individual screen. With this setup it is almost trivial to define in each screen (or panel) what the back button is supposed to go back to. You don't even have to have a stack for simple menu navigation scenarios, you just add a reference for the "back" button's panel in each panel.