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) {}
		}
}

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;
}
}
}

}

//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 :stuck_out_tongue:
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… :slight_smile:
i hope this is helpful for you.

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) {}
		}
}

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.