Making prefab duplicatable

EDIT: (Because it wasn’t too clear, and updated script)

My script still isn’t working correctly. I tried to instead of raycasting use mouseDown to try and localise it to the object. But because they’re both running the same script i’m getting undesirable results.

Here’s my ‘project’ (blank scene, and a default skybox) if someone would rather look at it directly than through my code. It was done in the latest version of unity for windows

I can get it to build a tower on a zone, but then the next time it’s clicked it’s supposed to show ‘destroy menu’ , however it gets confused between the two objects and gives strange results.

Help would be very much apprechiated

Here’s the script:
static Rect myRect;
static Vector2 mousePos;

	public GameObject zoneTower;
	string zoneTowerName; 

	int zoneTowerStength;
	int zoneTowerMinHealth; 
	int zoneTowerMaxHealth;
	int zoneTowerCurrHealth;

	public static bool showDetailsGUI = false;
	public static bool showBuildMenu = false;
	public static bool showDestroyMenu = false;

	static Vector3 dir;

	canon canonInstance; 
	buildCube cubeInstance; 

	public delegate void upgrade ();
	public static event upgrade UpgradeTower;

	Vector3 OnMouseDown(){

		print(this.gameObject.collider.name);

		if (!zoneTower) {
			
			if (Input.GetButtonDown ("Fire1")) {
				
				mousePos = new Vector2 (Input.mousePosition.x, Input.mousePosition.y);
				
				myRect = new Rect (mousePos.x, mousePos.y, 120, 110);
				
				showBuildMenu = true;

			}
			
		} else { 
			
			if (Input.GetButtonDown ("Fire1")) {
				
				mousePos = new Vector2 (Input.mousePosition.x, Input.mousePosition.y);
				
				myRect = new Rect (mousePos.x, mousePos.y, 120, 110);
				
				showDestroyMenu = true;
				
			}
			
		}

		dir = transform.position;
		
		return dir;

	}

		void OnGUI(){

			if (showBuildMenu == true) {
			showDestroyMenu = false;
			myRect = GUI.Window (0, myRect, buildWindow, "Build Window");

	    	}

			if (showDestroyMenu == true) {
			showBuildMenu = false;
			myRect = GUI.Window (1, myRect, destroyWindow, "Destroy Window");

			}

     }      //End OnGUI
	
	void buildCanon(Vector3 dir){

		zoneTower = canon.GetZoneTowerObj();
		zoneTowerName = canon.towerName;
		zoneTowerStength = canon.strength;
		zoneTowerMinHealth = canon.minHealth; 
		zoneTowerMaxHealth = canon.maxHealth;
		zoneTowerCurrHealth = canon.currHealth;

		Vector3 newDir = new Vector3(dir.x, 0.09f, dir.z);
		zoneTower = Instantiate (zoneTower, newDir, Quaternion.identity) as GameObject;
		zoneTower.name = zoneTowerName;
		showBuildMenu = false;

	}

	void buildCubes(){

		zoneTower = buildCube.GetZoneTowerObj ();
		zoneTowerName = buildCube.towerName;
		zoneTowerStength = buildCube.strength;
		zoneTowerMinHealth = buildCube.minHealth; 
		zoneTowerMaxHealth = buildCube.maxHealth;
		zoneTowerCurrHealth = buildCube.currHealth;
		
		Vector3 newDir = new Vector3(dir.x, 0.09f, dir.z);
		zoneTower = Instantiate (zoneTower, newDir, Quaternion.identity) as GameObject;
		zoneTower.name = zoneTowerName;
		showBuildMenu = false;

	}

	void buildWindow(int windowID) {

		if (GUI.Button (new Rect (10, 20, 100, 20), "Build Canon")) {

			buildCanon (dir);

		}

		if (GUI.Button (new Rect (10, 50, 100, 20), "Build Cube")) {

			buildCubes();

		}

	}//end domywindow

	void destroyWindow(int windowID) {
	
		if (GUI.Button (new Rect (10, 20, 100, 20), "Remove Tower")) {
			Destroy(zoneTower);
			showBuildMenu = false;
			showDestroyMenu = false;
		}

		if (GUI.Button (new Rect (10, 50, 100, 20), "Upgrade")) {
		
			UpgradeTower();
			showBuildMenu = false;
			showBuildMenu = false;
		}

		if (GUI.Button (new Rect (10, 80, 100, 20), "Return")) {
			showBuildMenu = false;
			showDestroyMenu = false;
		}

    }
	
}

you could add the prefab to you class

public GameObject myPrefab;

this way you just drag and drop your prefab to your class in editor, then in the moment when you need to duplicate your prefab you just instantiate it

GameObject.Instantiate(myprefab, myprefabnewpositition, Quaternion.Identity);

and that’s it, you instantiated a clone of your prefab, optional, you can access its properties if you set it to a variable

GameObject myPrefabClone = GameObject.Instantiate(myprefab, myprefabnewpositition, Quaternion.Identity) as GameObject;
myPrefabClone.name = "other name";
myPrefabClone.localScale = new Vector3(100f,100f,100f);//bigger, smaller