Trying to instantiate cubes randomly using only specified X and Z axis.
Basically, user should be able to input min and max values for random float generator, as well as number of prefabs to be spawned.
However, i spent hours trying to cheat this one, no luck. It’s probably very simple, just that i can’t access transform values anyhow. For what i see the reason, probably is because transform stores 9 values in total (position, rotation, scale), i can’t seem to access position values, multiply them and instantiate prefabs accordingly from a spawn point, not Vector3.zero
and yes, i want to stick to rigidbody
var cubePrefab : Rigidbody;
var numberOfCubes : int;
var randomRangeMin : float;
var randomRangeMax : float;
function Start(){
for (var i : int = 0; i < numberOfCubes; i++) {
var randomRange = Random.Range (randomRangeMin, randomRangeMax);
var pos = transform.position.Vector3 (randomRange, 0, randomRange);
Instantiate (cubePrefab, pos, Quaternion.identity);
}
}