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 Kourosh · Oct 05, 2010 at 04:21 PM · guilinkpage

What is the best way to define different GUI pages?

How can I link between 2 or more pages of GUIs? I'm trying to make different javascript files each containing a different GUI and I try to enable one and disable others to link between them, but that just doesn't feel right? is there any better way? 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

2 Replies

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

Answer by Jesse Anders · Oct 05, 2010 at 05:02 PM

Maybe someone will offer a better answer, but I don't know that there's any one 'right' answer to the question. Really, I think it's just a question of what best meets your needs and seems sufficiently practical/elegant/etc.

Assuming it works as you expect, enabling and disabling as needed doesn't seem inappropriate to me. Other options/variations that spring to mind are:

  • Make the individual menu objects children of a 'menu manager' object that handles switching between them.

  • Use a static member variable to keep track of which menu is currently active.

  • Put all the menus in one script, put each individual menu in its own function, and then call the appropriate function from OnGUI().

I can't remember what sort of menus the various tutorial projects include, but if they do have menus, you might check there to see how they handle things.

Comment
Add comment · Show 2 · 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 Kourosh · Oct 06, 2010 at 08:36 AM 0
Share

Is there any tutorial you recommend? cause now I'm stuck among many variables each for fading in and out each menu and its totally confusing. I mean is there any way that these GUIs could simply link to each other like a website?

avatar image Jesse Anders · Oct 06, 2010 at 04:55 PM 0
Share

I don't know of any tutorials that cover specifically what you're describing (although there may be some). As for 'linking' the pages in some sort of automatic way, there's no built-in Unity feature that will do that directly. But, it shouldn't be a problem, I$$anonymous$$O; many if not most games implement multi-page menus in one form or other, so obviously it's not an intractable problem. Really, it's just a software design issue. (If you set things up appropriately, each menu should only need a couple of variables for fading, which isn't too bad.)

avatar image
0

Answer by ManickYoj · Aug 28, 2014 at 04:11 AM

I have an add-on to Jesse Anders' comment about making the individual menu objects children of a menu manager. I implemented a version of that and have included the code below.

The basic gist is that you have a manager class with a reference to your current menu. The manager class then calls an update method on the current menu, and that current menu's update method returns the current menu if you have not navigated to a new menu, and the new menu if you have.

In this example, I have a main menu with a "SubMenu" Button that loads up a Sub-Menu. The Sub-Menu has a back button which returns you to the previous menu.

 using UnityEngine;
 
 public class MenuManager : MonoBehaviour {
     private IMenu menu = new MainMenu();
     
     void OnGUI () { menu = menu.update (); }
 }
 
 public interface IMenu { IMenu update (); }
 
 public class MainMenu : IMenu {
     public IMenu update() {
         if (GUI.Button(new Rect(100, 100, 250, 100), "SubMenu")) return new SubMenu(this);
 
         return this;
     }
 }
 
 public class SubMenu : IMenu {
     private IMenu prevMenu;
 
     public SubMenu (IMenu prevMenu) { this.prevMenu = prevMenu; }
 
     public IMenu update() {
         if (GUI.Button(new Rect(100, 100, 250, 100), "Back")) return prevMenu;
 
         return this;
     }
 }
 

Hope this helps!

Comment
Add comment · 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

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

1 Person is following this question.

avatar image

Related Questions

Can I place a link (such as ) into the GUI.Label? 4 Answers

4.6 GUI Button inside a scrolling Text Box 0 Answers

How do you make a web page come up without quitting your Unity game? 1 Answer

textfield and button submit 1 Answer

HTML text box in iPhone Unity? 0 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