Instantiate is only spawning at one pos, no matter what I do.

Just as the title says, Instantiate is only spawning an object at a single position. No matter what values I change. Here’s my code:

// Spawns objects at current location \\

var time : int = 5;
var randomLocationVertical : float = 15;
var randomLocationHorizontal : float = 10;

var randomLocation : Vector3;
var object : GameObject;
var object2 : GameObject;

private var countTime : float = 0;

function Update () {

	countTime += Time.deltaTime;
	
	randomLocation = Vector3(Random.Range(randomLocationHorizontal-5, randomLocationHorizontal), Random.Range(randomLocationVertical-5, randomLocationVertical), 0);
	
	if(countTime >= time) {
		Debug.Log(transform.position);
		Instantiate (object, transform.position + randomLocation , Quaternion.identity);
		countTime = 0;
	}

}

randomLocation is already a Vector3, so you don’t need to declare that a second time.

Try replacing

randomLocation = Vector3(Random.Range(randomLocationHorizontal-5, randomLocationHorizontal), Random.Range(randomLocationVertical-5, randomLocationVertical), 0);

with

randomLocation = Random.Range(randomLocationHorizontal-5, randomLocationHorizontal), Random.Range(randomLocationVertical-5, randomLocationVertical), 0;

If that doesn’t work, you may need to declare each xyz value for randomLocation individually… Something like:

randomLocation.x = Random.Range(randomLocationHorizontal-5, randomLocationHorizontal);

Good luck! :slight_smile: