Search Unity

Creating a variable for GUI.Button, is it possible?

Discussion in 'Immediate Mode GUI (IMGUI)' started by bloxybox, Mar 5, 2015.

  1. bloxybox

    bloxybox

    Joined:
    Jan 11, 2015
    Posts:
    3
    Hi, my problem is every time I try to use this script I get an error. It says "Unexpected symbol 'public", I don't know if I'm just writing my variable wrong or if I'm doing everything wrong, but some help would be appreciated. I'm basically making a GUI Button, it appears fine and it lets me click to the first Level like I want it to, but I wanted to disable it after it goes to the first level. Should be pretty simple, but I'm probably thinking about it too hard. This is the script, thanks:

    using UnityEngine;
    using System.Collections;

    public class MainMenu : MonoBehaviour {

    public GUISkin gSkin;

    void OnGUI () {
    public bool menubutton= GUI.Button(new Rect(Screen.width/2,Screen.height/2,250,100), "Play"); //line where the error consists
    if (menubutton)
    Application.LoadLevel(0);
    menubutton = false;

    }
    }
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667