GUI Button Question

Hello, the question i have is can you turn off certain parts of a script, for example i have 2 GUI Buttons but while ones on i dont want the other one one, but i dont want to make 2 separate scripts is there anyway to make it so that while ones on the the other cant be on, even thought there in the same script?

Sure thats not a problem. There are a couple of approaches to this. Depending on the depth of the script you will favor one over the other. Firstly you could use a boolean method

var showSetOne:boolean;

function OnGUI()
{
    if(showSetOne)
    {
        if(GUI.button(.....))//Do something
        if(GUI.button(.....))//Do something
    }
    else
    {
        if(GUI.button(.....))//Do something
        if(GUI.button(.....))//Do something
    }
}

Now if your menu/gui setup is much more complex than just have 2 dimensions, you should use a switch case approach

var menu:int;

function OnGUI()
{
    switch(menu)
    {
        case 0:
            //ShowGUIForGroupZero
            if(GUI.Button(.....))menu=1;
            if(GUI.Button(.....))menu=2;
            if(GUI.Button(.....))menu=3;
        break;
        case 1:
            //ShowGUIForGroupOne
            if(GUI.Button(.....))menu=2;
        break;
        case 2:
            //ShowGUIForGroupTwo
            if(GUI.Button(.....))menu=3;
        break;
    }
    //Anything outside of the switch-case with be shown regardless of menu
}

i am guessing what you want to do is differentiate between your home page GUI [play btn,options btn, settings btn]and your in scene GUI[score,time]… so that when one shows other dosent and you want to do this in one script.

here’s what you do:

private bool menu;

void Start()
{
menu = true;
}

void OnGUI()
{
if(menu)
{
//your homepage GUI goes here
if(GUI.Button(new Rect(10,10,10,10),"PLAY"))
{
menu = false;
}
}
else
{
//your scene GUI goes here
//make menu = true when u want to display homepage GUI again.
}
}

using UnityEngine;

    using System.Collections;
    
    public class BUTTONS2 : MonoBehaviour {
    
    private bool menu;
    
    // Use this for initialization
    
    void Start () {
    
    menu = false;
    
    }
    
    // Update is called once per frame
    
    void Update () 
    { 
    
    }
    
    void OnGUI()
    {
    
    if(menu)
    {    
    if(GUI.Button(new Rect(100,10,100,100),"PLAY2")) 
    { 
    menu = false;
    GetComponent().enabled = true; 
     } 
    } 
    else 
    { 
   if(GUI.Button(new Rect(100,10,100,100),"PLAY1")) 
    {
       menu = true; 
       GetComponent().enabled = false; 
   }
    } 
    } 
    }

your code in a better way… no need update…your just redoing what can be done in OnGUI()…