How to execute script

Hi, I made a new script with the following code:

function OnGUI () {
	if (GUI.Button (Rect (10,10,150,100), "I am a button")) {
		print ("You clicked the button!");
	}
}

If I enter the ‘Game-mode’, the button is not visible. Should I assign the button to an object in the Hierarchy?

Thanks!

Monobehaviours overriden functions (OnGUI, Update, Start, those sorts of things) are executed for each objects they are attached to. So if you want Unity to call them, you HAVE to attach your script to an object. It can be an empty on, with just the transform component, as long as it is in the scene.