- Home /
Random Position Script
I'm making a script to generate power-ups. So far this is what I have:
var prefab : Transform; var timer = 10.0; var countdown = 1.0; var xpos = 0; var ypos = 0; var zpos = 0;
function Update () { if (timer > 0) { timer -= countdown * Time.deltaTime; } if (timer < 0) { timer = 0; } if (timer == 0) { Instantiate (prefab, Vector3(xpos, ypos, zpos), Quaternion.identity); timer = 10.0; } }
How can I impliment a function that will cause the position of the objects spawn to change each time? I need to be able to change the variables xpos and zpos (x and z posisions) to anywhere from 0 to 25. I know the Range function will do this, but I don't know how to correctly type the script. Can someone show me a simple script to generate a random number from 0 to 25?
Answer by DaveA · May 16, 2011 at 11:46 PM
var rx = Random.Range(0,25); // integer
var rx = Random.Range(0.0,25.0); // float
Did you look at http://unity3d.com/support/documentation/ScriptReference/Random.Range.html ?
Thanks, and no I never saw that one, but I'll go take a look to get a better understanding.
Your answer
