- Home /
Turning off ONE GUI button
Hello Everyone,
I've searched all over the internet for hours and can't find the answer. I want my GUI.Button to disappear when I click it. I can't seem to do it. Using enabled=false turns all GUI off, but I want only the button to disappear. Currently, after I click the button, the rest of my GUI appear, but right over the button, which stays visible.
I appreciate your help. -Hyperion
Answer by tw1st3d · Oct 05, 2013 at 12:12 AM
Try using a bool.
using System.Collections;
using UnityEngine;
public class DisappearingButton : MonoBehavior
{
protected bool showButton1 = true, showButton2 = true;
public void OnGUI()
{
if(showButton1)
if(GUI.Button(new Rect(10, 20, 100, 20), "Turn Off 1"))
showButton1 = false;
if(showButton2)
if(GUI.Button(new Rect(10, 45, 100, 20), "Turn Off 2"))
showButton2 = false;
}
}
This is what I would tell the OP in my answer, so I'll just say +1 to you :D
Thanks, I'm glad to know that I'm going in the right direction with my program$$anonymous$$g. Been kind of doubting myself with it since I keep getting stuck on tiny things for days.
Thank you! All the other answers I looked at were super ambiguous and resulted in headaches.
It gets frustrating, I'm still learning myself. Always stick w/ it though man, well worth the time and effort :)
Your answer
Follow this Question
Related Questions
Button Turns Off and On Object 1 Answer
Button then instanitates gameobject 1 Answer
How to hook up the particle system to jump animation? 1 Answer
Make more buttons appear, on button click. 1 Answer
GUI Button Animation Cue 1 Answer