Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Abby 1 · May 13, 2011 at 10:48 AM · buttonback

Go Back Button Script

I've create a game menu, a pause menu and an instruction screen and on the instruction screen I have an an arrow that 'goes back,' however at the moment the arrow has a script that has 'Application: loadlevel' setting in it and it loads back to the main menu only.

I need a script so that when I click the arrow it goes back to the previous 'setting' instead of it loading the menu; when I press pause, instructions then the arrow button, I want it to go back to the pause screen.

Thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by CHPedersen · May 13, 2011 at 11:01 AM

To implement a "Back"-button you need to introduce some kind of record of where you've just been in the GUI. Unity's GUI system invites the creation of state machine-GUIs where one state might correspond to, say, one window being displayed. So to swap between windows, you have to keep track of the previous states.

Try something like this:

string menuPosition = "MainMenu"; string previousPosition = "";

void OnGUI() { switch (menuPosition) { case "MainMenu": DrawMainMenuScreen(); break; case "Settings": previousPosition = "MainMenu"; DrawSettingsScreen(); break; case "Load Game": previousPosition = "MainMenu"; DrawLoadDialog(); break; .etc .etc .etc default: break; } }

Then in lower windows, like the SettingsScreen(), if your Back-Button is clicked you set menuPosition = previousPosition to cause the next call to OnGUI to draw whatever came before. Keep in mind that the above is extremely simplified - First off, the menuPosition probably shouldn't be a string, but an enum. Secondly, the states should probably enter and leave a Stack datastructure to automate the retrieval of the previousPosition, instead of setting it manually every time.

The key is to introduce state memory. Keep track of where you are and just have been in the GUI.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Abby 1 · May 13, 2011 at 11:20 AM 0
Share

O$$anonymous$$ thanks, I'll give it a try and work round it.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to place button inside window same place 1 Answer

Unity backbutton crashes while on first scene 0 Answers

Button back not clickable after rotation animation 1 Answer

Unity UI How to make Multiple Clickable Next / Back Buttons? 3 Answers

Back button issue: when I use back button to close keyboard, it also close the scene. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges