I've no problems with the other scripts, only when I add in the OnMouseDown function it can't compile the script. I think I'm doing it wrong, but what's the correct way of doing it?
Official way is probably to use a `GUI.toggle` with a GUIstyle. In the inspector, `OnNormal` is what it looks like when it is clicked on. The scripting reference has the rest. A toggle is a button the "remembers" On/Off.
`OnMouseDown` is a function, so can't go inside another function. that's why it's made at you. If you really want it that way, use `Input.GetButtondown(0)` (or look in the Input scripting section for other options.) But, that first if is already checking the button for you.
That's all you need to make a Statebutton. If you want to turn it green on activation, set it's background-color:
Color c=GUI.backgroundColor; // store value
if (buttonstate)
GUI.backgroundColor=Color.green;
buttonstate=GUILayout.Toggle(buttonstate, "Light 1","button");
GUI.backgroundColor=c; // reset to old value
Based on that, I came up with this, and it works perfectly for me. =)
var lights : Light[];
//For the custom GUI skin
var guiSkin : GUISkin;
//For the toggle to work
var toggleBool1 : boolean = false;
//For the size and placement of the buttons
private var toggleRect1 = Rect(25, 25, 100, 20);
function OnGUI()
{
//To change the button's texture when its activated
toggleBool1 = GUI.Toggle(toggleRect1, toggleBool1, "LightSwitch 1", guiSkin.button);
//To make my light respond to the toggle switch.
lights[0].enabled = toggleBool1;
}
Now I can make a toggle (that looks like a button) turn green when its activated, and stay green until I click it again.
For the texture of the button when its pressed I used a .png file thats just green.
PS. Thanks Duck and everyone who helped by answering also! =D