How do I spawn an object when a button is touched? 2D game

Hi,I’m a newbie to Unity and scripting. Looking through other questions I have a general idea about how to spawn an object when you touch a mobile screen. However, I am not completely sure about how to spawn when a gui button is touched. I’ve already looked through the Input.GetTouch documentation. I’m also trying to spawn the object into a 2d game

Can anyone provide some basic javascript that could instantiate an object when a gui button is tapped? Where the object is spawned could just be any fixed position thats visible. Does spawning differ in 2d games?

var spawnPosition : Transform;
var object : GameObject;

funtion OnGUI()
{
//create a button
    if (GUI.Button(Rect(10,10,200,20),"Spawn"))
         Instantiate(object,spawnPosition.position,spawnPosition.rotation);
//       ^^ Instantiate the object

}