How to instantiate prefab on top of object

Here is the code i’m using:
#pragma strict

var showGUI = false;
var laserTurret : GameObject;

function OnMouseDown()
{
	if(showGUI == true)
	{
		showGUI = false;
	}
	else
	{
		showGUI = true;
	}
}

function OnGUI()
{
	if(showGUI == true)
	{
		var instance : GameObject = Instantiate(laserTurret, transform.position, transform.rotation);
		showGUI = false;
	}
}

function Start () {

}

function Update () {

}

But the result is that the object spawn’s in a random place which is not on top of the gameobject

The position isn’t ‘random’. Your code places it at the position of the game object this script is attached to. I don’t know how you have thing setup. My suggestion is to place an empty game object at the position where you want to instantiate the ‘laserTurret’. Then make that empty game object a child of whatever object you want to add a ‘laserTurret’ to. The script above goes on the empty game object.