How to use that script with a on Click (on active) ?

Hi,

I would like to know if it’s possible to modify that script to use it with an on click.

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
public string lastTooltip = " ";
void OnGUI() {
GUILayout.Button(new GUIContent("Play Game", "Button1"));
GUILayout.Button(new GUIContent("Quit", "Button2"));
if (Event.current.type == EventType.Repaint  GUI.tooltip != lastTooltip) {
if (lastTooltip != "")
SendMessage(lastTooltip + "OnMouseOut", SendMessageOptions.DontRequireReceiver);

if (GUI.tooltip != "")
SendMessage(GUI.tooltip + "OnMouseOver", SendMessageOptions.DontRequireReceiver);

lastTooltip = GUI.tooltip;
}
}
void Button1OnMouseOver() {
Debug.Log("Play game got focus");
}
void Button2OnMouseOut() {
Debug.Log("Quit lost focus");
}
}

to do something on click you just have to do :

if ( GUILayout.Button(new GUIContent("Play Game", "Button1") )
{
Debug.Log("Play has been clicked");
}

Click is handle by unity, so you don’t have to use tricks needed for rollover/rollout :wink:

lol i really need to get some sleep, sorry about that…