• 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
0
Question by RKM_91 · Apr 12, 2015 at 02:29 PM · mainmenu

Main Menu Problem?

Hello Unity Answers,

I have created a main menu, and the problem I'm having is when I click either Instructions or Exit text/button both pop up boxes appear instead of If I clicked Instructions, then the UI image on the left appears and if I click Exit the UI image on the right appears. .

All ideas, help, suggestions welcome.

alt text

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class menuScript : MonoBehaviour {
 
     public Canvas quitMenu;
     public Canvas instructionMenu;
     public Button startText;
     public Button instructionText;
     public Button exitText;
 
 
 
     // Use this for initialization
     void Start () 
     {
         quitMenu = quitMenu.GetComponent<Canvas> ();
         instructionMenu = instructionMenu.GetComponent<Canvas> ();
         instructionText = instructionText.GetComponent<Button>();
         startText = startText.GetComponent<Button> ();
         exitText = exitText.GetComponent<Button> ();
         quitMenu.enabled = false;
         instructionMenu.enabled = false;
     }
 
     public void ExitPress()
     {
         quitMenu.enabled = true;
         instructionMenu.enabled = true;
         startText.enabled = false;
         instructionText.enabled = false;
         exitText.enabled = false;
     }
 
     public void NoPress()
     {
         quitMenu.enabled = false;
         instructionMenu.enabled = false;
         startText.enabled = true;
         instructionText.enabled = true;
         exitText.enabled = true;
 
     }
 
     public void StartLevel()
     {
         Application.LoadLevel (1);
     }
 
     public void ExitGame()
     {
         Application.Quit ();
     }
     
 
 }
 




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
1
Best Answer

Answer by DiegoSLTS · Apr 12, 2015 at 02:49 PM

In your ExitPress function your showing both menus:

      public void ExitPress()
      {
          quitMenu.enabled = true;
          instructionMenu.enabled = true;
          ...
      }

And since that's the only function that sets the menus to true I guess you registered that function to both buttons.

Try splitting that function in 2, each one setting only one menu to true, and register each one to a different button.

And a little suggestion, all those "GetComponent" lines in the Start method are useless, you can remove them. You already have a reference to Canvases and Buttons so you don't need to get the Canvas and Button components of those references.

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 RKM_91 · Apr 12, 2015 at 03:04 PM 0
Share

Thank you very much, simple & understandable explanation. :)

avatar image
0

Answer by KalleH · Apr 12, 2015 at 02:35 PM

Try lowering the height of the buttons or moving them further away from each other because it's possible that the buttons overlap which would cause this problem.

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 RKM_91 · Apr 12, 2015 at 02:39 PM 0
Share

I have moved the buttons furtheraway from each other but the problem still remains?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Changing two different objects renderer colour 1 Answer

How can I add a UI (Main Menu) with function. 0 Answers

i made a script called pause menu.when someone click on main menu option it sents to the main menu.The script works perfectly but on main menu the options start and quit game are not responding.help me.here's the script. 1 Answer

GameObject duplicates every time my GUI button is pressed 1 Answer

Can't go back to the game scene from main menu for the second time 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