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
0
Question by HarbingerOfMe · Dec 04, 2012 at 03:43 PM · guibuttonmouseonguidouble

Menu button needs to be double clicked.

Hello, I'm trying to create a menu of which one of the buttons makes himself and the other buttons dissappear, and another one appear. I'm using the code

below, but the issue with this is that user CURRENTLY NEEDS to double click the show/hide button to make the menu (dis)appear.

 using UnityEngine;
 using System.Collections;
 
 public class DelegateMenu : MonoBehaviour 
 {
        //De variabelen definieren.
         private delegate void MenuDelegate();
 
         
         private MenuDelegate menuFunction;
  
        
         private float screenHeight;
         private float screenWidth;
         private float buttonHeight;
         private float buttonWidth;
     
         private bool menuweergeven = false;
         private bool menucreeren = false;
         private bool menuladen = false;
         private bool menuinfo = false;
         private bool menuopties = false;
  
           
         void Start ()
         {        
                 //de constante variabelen aanroepen.
                 screenHeight = Screen.height;
                 screenWidth = Screen.width;
   
                 buttonHeight = 27;
                 buttonWidth = 130;
   
         }
  
         void OnGUI()
         {
             if (menuweergeven==false) 
             {
                 //de variabelen aanroepen en uit laten voeren.
                 if(GUI.Button(new Rect(3,3,buttonWidth, buttonHeight), "Molecuul weergeven"))
                 { Debug.Log ("buttonclicked");
                         menuweergeven = true;
                 }
                 if(GUI.Button(new Rect(3,3+buttonHeight*1.1f,buttonWidth, buttonHeight), "Molecuul creeren"))
                 {
                         menucreeren = true;
                 }
                 if(GUI.Button(new Rect(3,3+buttonHeight*2.2f,buttonWidth, buttonHeight), "Molecuul laden"))
                 {
                         menuladen = true;
                         Debug.Log ("je moeder");
                 }
                 if(GUI.Button(new Rect(3,3+buttonHeight*3.3f,buttonWidth, buttonHeight), "Informatie"))
                 {
                         menuinfo = true;
                 }
                 if(GUI.Button(new Rect(3,3+buttonHeight*4.4f,buttonWidth, buttonHeight), "Opties"))
                 {
                         menuopties = true;
                 }
   
                 if(GUI.Button(new Rect(3,3+buttonHeight*5.5f,buttonWidth, buttonHeight), "Afsluiten"))
                 {
                         Application.Quit();
                 }
             }
         
         if (menuweergeven==true) 
             {
             if(GUI.Button(new Rect(3,3+buttonHeight*6.6f,buttonWidth, buttonHeight), "Menu weergeven"))
                 {
                 menuweergeven = false;
                 }
             }
         //removing pesky warnings
         if (menucreeren) {}
         if (menuladen) {}
         if (menuinfo) {}
         if (menuopties) {}
         }
 }
Comment
Add comment · Show 1
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 deltamish · Dec 04, 2012 at 04:38 PM 0
Share

hi, I cant understand your script please reupload the script or go to edit and then select your codes(script) and then press the button saying(101010) in the screen

Now lets come back to the topic 1.I will post the solution to your problem once you reupload the script.

first

do you want to add custom button(with custom texture) or do you want Unity's inbuilt button both of them are easy to be scripted,I am asking this because you mentioned you were making a menu.

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by deltamish · Dec 11, 2012 at 01:08 PM

Hi, Sorry for the late reply .There was a problem with my PC.

I am getting a bit confused with your script(Dutch part) But If you trying to make a button disappear when click on a button

try this example

 using UnityEngine;
 using System.Collections;
 
 public class MainMenuTest : MonoBehaviour 
 {
 public bool Campaign = false;/////////I am making it public so that you can see what is happening
 public bool Options = false;
 
 
 public float buttonheight;
 public float buttonwidth;
 
 void Start(){
 
 }
 
 void Update(){
 if(!Campaign && !Options){////Same as if(Campaign == false)///This is checking if we have pressed Campaign button or not 
 if(GUI.Button(new Rect(20,110,buttonwidth,buttonheight),"Campaign")){
 Campaign = true;
 }
 if(GUI.Button(new Rect(20,140,buttonwidth,buttonheight),"Options"){
 Options = true;
 
 }
 
 }
 if(Campaign){/////////Same as if(Campaign == true)
 if(GUI.Button(new Rect(20,530,buttonwidth,buttonheight),"Back")){
 Campaign = false;
 }
 if(GUI.Buton(new Rect(20,140,buttonwidth,buttonheight),"Start")){
 Application.LoadLevel(1);
 }
 }
 if(Options){
 if(GUI.Button(new Rect(20,110,buttonwidth,buttonheight),"Audio")){
 ////your Audio decrease or increase code
 
 }
 if(GUI.Button(new Rect(20,530,buttonwidth,buttonheight),"Back")){
 Options = false;
 }
 }
 }
 
 }
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
avatar image
0

Answer by azmat786n · Dec 04, 2012 at 05:06 PM

 //var for check first click
 private boolean ClickOne = false;
 
 //auto disable 1st click after given time
 Void fstClick() {
     //1st cilck enable
     ClickOne = true;
     yield WaitForSeconds(0.3);
     //disable after above time waiting
     ClickOne = false;
 }
 
 Void OnGUI() {
     if(GUI.Button(Rect(Screen.width/2-200,Screen.height-70,100,60), "click")) {
         //if first click enable then execute the function.
         if(ClickOne) {
        Debug.Log("clicked");
     }
         //this will enable first click make button double click
     fstClick();
     }
 }

we can't understand your problem looking above question but you have a good title of your Question :P so i have a script for double click menu button you can use it i am a javascript Developer so don't know this one is bug free or not.. :) i hope this is helpful for you.

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
avatar image
0
Wiki

Answer by HarbingerOfMe · Dec 04, 2012 at 10:31 PM

Algiht, let's try this again. I'm trying to create a menu, but the problem is that the current script only works if an user double clicks the hide menu button. I can't figure out why. Below is the script (and hopefully it stays as 1 codeblock)

 using UnityEngine;
 using System.Collections;
 
 public class DelegateMenu : MonoBehaviour 
 {
        //De variabelen definieren.
         private delegate void MenuDelegate();
 
         
         private MenuDelegate menuFunction;
  
        
         private float screenHeight;
         private float screenWidth;
         private float buttonHeight;
         private float buttonWidth;
     
         private bool menuweergeven = false;
         private bool menucreeren = false;
         private bool menuladen = false;
         private bool menuinfo = false;
         private bool menuopties = false;
  
           
         void Start ()
         {        
                 //de constante variabelen aanroepen.
                 screenHeight = Screen.height;
                 screenWidth = Screen.width;
   
                 buttonHeight = 27;
                 buttonWidth = 130;
   
         }
  
         void OnGUI()
         {
             if (menuweergeven==false) 
             {
                 //de variabelen aanroepen en uit laten voeren.
                 if(GUI.Button(new Rect(3,3,buttonWidth, buttonHeight), "Molecuul weergeven"))
                 { Debug.Log ("buttonclicked");
                         menuweergeven = true;
                 }
                 if(GUI.Button(new Rect(3,3+buttonHeight*1.1f,buttonWidth, buttonHeight), "Molecuul creeren"))
                 {
                         menucreeren = true;
                 }
                 if(GUI.Button(new Rect(3,3+buttonHeight*2.2f,buttonWidth, buttonHeight), "Molecuul laden"))
                 {
                         menuladen = true;
                         Debug.Log ("je moeder");
                 }
                 if(GUI.Button(new Rect(3,3+buttonHeight*3.3f,buttonWidth, buttonHeight), "Informatie"))
                 {
                         menuinfo = true;
                 }
                 if(GUI.Button(new Rect(3,3+buttonHeight*4.4f,buttonWidth, buttonHeight), "Opties"))
                 {
                         menuopties = true;
                 }
   
                 if(GUI.Button(new Rect(3,3+buttonHeight*5.5f,buttonWidth, buttonHeight), "Afsluiten"))
                 {
                         Application.Quit();
                 }
             }
         
         if (menuweergeven==true) 
             {
             if(GUI.Button(new Rect(3,3+buttonHeight*6.6f,buttonWidth, buttonHeight), "Menu weergeven"))
                 {
                 menuweergeven = false;
                 }
             }
         //removing pesky warnings
         if (menucreeren) {}
         if (menuladen) {}
         if (menuinfo) {}
         if (menuopties) {}
         }
 }
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
avatar image
0

Answer by Shgoedt · Dec 09, 2012 at 08:55 PM

What are you trying to do? You want the buttons to (dis)appear when another button is double clicked?

Out of the top of my head, since you have 30 vars anyway, make an public int timesClicked; and let that update by 1 if the button is clicked, and then check if(timesClicked >= 2){} ??

Also, remove the dutch vars, confuses people.

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

12 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

Related Questions

Specify OnMouseEnter 2 Answers

GUI.DrawTexture on GUI.Button press 1 Answer

[FIXED] Why is my GUI.Button always pressed? 0 Answers

Dynamic created button at Mouse Location Moving 0 Answers

How to give animation to the on gui button? 1 Answer


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