Why are my GUI Buttons Triggering automaticaly

I’m trying to make a menu for my game using GUI buttons, I followed the instructions at :Unity - Manual: Controls and put code in to be used once the button is clicked, the problem i’m having is that when i start my game it will open normally and after about half a second it will trigger the code for when I click the button, without me clicking them.

#pragma strict

private var Options : boolean;
var OptionsGUI : GameObject;
var MenuGUI : GameObject;

function OnGUI()
{
	if(GUI.Button(Rect(175, 210, 400, 75),"O P T I O N S"));
	{
		SetOptions();
	}
}
function SetOptions ()
{	
//this code is what i'm using to switch between GUI i tested it and it works
	OptionsGUI.GetComponent(options).enabled = true;
	MenuGUI.GetComponent(menu).enabled = false;
}

Remove the semi-colon from the end of this line:

     if(GUI.Button(Rect(175, 210, 400, 75),"O P T I O N S"));

The ‘;’ terminates the ‘if’ so that the SetOptions() call is made every frame.

The problem is the ; at the end of line 9. Remove it and everything will work.

Credit for this answer goes to @robertbu. UA ate his original answer.

Instead of creating Set options functions within the script why don’t you try to create another script containing the function then attach it to the gameobject, call the script attached to the gameobject and then call the function inside the if statement. because in the case of your script the function would automatically run every time the script executes. you may use Gameobject.Find(“nameOfYourGameObject”).GetComponent(name of script); to get the script.