Hi,
I’m a c# novice learning as I go. Currently I’m trying to write a c# script where a gui.button appears and then once clicked it’d make itself disappear. I’m doing this by only making the button appear if bool showMessage us true. What’s supposed to happen is that once the button gets clicked, showMessage will become false, which in turn should the button NOT appear. Am I missing something?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CreateMessage : MonoBehaviour {
string message = "Hellow world";
bool showMessage = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
showMessage = true;
if (showMessage == true)
{
if (GUI.Button(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 100, 200, 200), message))
{
showMessage = false;
}
}
}
}