UI button doesn't appear - c#

Hi

In my game when the player falls of the edge and touches a trigger a gui buttom should appear however it doesn’t.

using UnityEngine;
using System.Collections;

public class GameOver : MonoBehaviour {

	public GameOverScript GameOverVar;

	public bool isClicked = false;

	bool guiOn = false;

	public float OnX = 15f;
	public float OnY = 15f;
	public float width = 100f;
	public float height = 50f;
	public string textInGUI = "Try again?";

	void OnTriggerEnter2D (Collider2D over)
	{
		if(over.gameObject.tag == "Player")
		{
			GameOverVar.isGameOver = true;
			if (GameOverVar.isGameOver == true)
			{
				//Application.LoadLevel(1);
				guiOn = !guiOn;
			}
		}
	}
	void OnGUI()
	{
		if(guiOn)
		{
			GUI.Button(new Rect(OnX,OnY,width,height), textInGUI);
			Debug.Log("It worked");
			guiOn = false;
		}
	}
}

Also the Debug.Log(“It worked”); does output in the console

By setting guiOn to false immediatly after displaying it you only display it for one frame. Just remove the guiOn = false or maybe put it like this:

     void OnGUI()
     {
         if(guiOn)
         {
             if(GUI.Button(new Rect(OnX,OnY,width,height), textInGUI))
             {
                 Debug.Log("It worked");
                 guiOn = false;
             }
         }
     }

The right code, and have been tested so it works.

if(guiOn) 
    { 
    bool button = GUI.Button(new Rect(OnX,OnY,width,height),textInGUI); 
    if(button) 
    { 
    Debug.Log("It worked"); 
    guiOn = false; 
    } 
    }

The problem here is that once you make guiOn false it hides the button because the button will only show as long as guiOn is true. Try to make guiOn false once the player has clicked on the button you cando this all at once like this.

if(guiOn)
{
if(GUI.Button(new Rect(OnX,OnY,width,height), textInGUI))
{
Debug.Log("It worked");
             guiOn = false;
}
}

This should work. And it creates the button so just replace that code with this one.