randomise spawnpoints position

hey, Im trying to make it so when turrets run out a spawn point spawns a turret at its position, then it randomizes a new position were the next one will spawn(the order in which that happens doesn't matter) for any wierd reason it spawns one, then moves to an other position(the same one each time) and stays there and spawns all the others right there. so here is the code Im using.

#pragma strict
var player : String;
var ObjectToDeploy : GameObject;
var deploied = true;
var turretCount : float;
var range1 : Transform;
var range2 : Transform;

function Update () {
Debug.Log("turretCount:"+turretCount);

	if (turretCount <= 0){
		
		Deploy ();
		
	}

}





function Deploy()
{
	if (deploied){
     Instantiate(ObjectToDeploy, transform.position, transform.rotation);
     deploied = false;
     transform.position.x = Random.Range(range1.position.x, range2.position.x);
     transform.position.x = Random.Range(range1.position.y, range2.position.y);
     }
}

function TurretCountAdd () {
	turretCount += 1;
	deploied = true; 

}
function TurretCountReduce () {
	turretCount -= 1;
}

Thank you all and sorry for any spelling mistakes.

Because you are actually not changing the position of the newly instantiated object, but, the old one. Also, You might want to randomize before initiation.

Try this…

function Deploy()

{

var RandomVec3 = Vector3 ( Random.Range ( x, x ), transform.position.y, transform.position.z ) ;

if (deploied){

 Instantiate(ObjectToDeploy, RandomVec3, transform.rotation);

 deploied = false;

 }

}

function TurretCountAdd () {

turretCount += 1;

deploied = true; 

}

function TurretCountReduce () {

turretCount -= 1;

}

In the code that you have posted, you are randomly setting the ‘x’ component of your deployment point’s position twice. I expect you want to update x and z. Since the second random selection is based on the ‘y’ component of your two reference points, I’m also willing to bet that the reason you see no change in position after the first placement is because they are located at the same height.

As mentioned in another answer, your deployment point is hopping around the map and turrets being placed at its location. Is that really what you want? I suppose it could be useful to see where the next turret will appear, before it spawns, but there are other ways to do that. You want some code? Here’s some code:

function Deploy()
{
    if (deploied){
     Instantiate(ObjectToDeploy, transform.position, transform.rotation);
     deploied = false;
     transform.position.x = Random.Range(range1.position.x, range2.position.x);
     transform.position.z = Random.Range(range1.position.z, range2.position.z);
     }
}