Hi people,
I’ve set up a script with a number of toggle buttons. I have them switching on and off when clicked which is fine. When clicked, a function is performed, but it keeps sending the message. What I want to do is just send a single message/action once. This is obviously a standard button action, but I couldn’t figure out how a button could have an on/off state; change graphic when touched.
Here’s my code:
#pragma strict
var LeftNavSkin: GUISkin;
//var toggle = true;
var bt1 = false;
var bt2 = false;
var bt3 = false;
// Clears everybody and returns true to help setting the desired one
function setMeOnly():boolean{
bt1 = bt2 = bt3 = false;
return true;
}
function OnGUI () {
GUI.skin = LeftNavSkin;
GUI.Box (Rect (-30,10,100,90), "");
//Top Left Button
if (GUI.Toggle (Rect(50,300,100,100), bt1, "")) bt1 = setMeOnly();
//Middle Button
if (GUI.Toggle (Rect(50,410,100,100), bt2, "")) bt2 = setMeOnly();
//Bottom Right Button
if (GUI.Toggle (Rect(50,520,100,100), bt3, "")) bt3 = setMeOnly();
//This sends the debug.log repeatedly. I want it to just send once.
if(bt1 === true)
{
Debug.Log("OMG IT WORKS");
}
}
Help would be appreciated!
Rich