I have a script, which spawns a random amount of gameobjects, at a random place on the screen, at a specific time, I would like this time to be random, so that the objects spawn at a random time, like if it was a random time between (1,5) but I can’t seem to figure out how to implement it in to my script, I know it has something to do with random.range, as I have used at another place in the script, but I dont know how to implement it for the timer.
My Script so far.
var Mines : Transform;
private var Timer : float;
function Awake () {
Timer = Time.time + 4;
}
function Update () {
var randNum = Random.Range(0, 3); // this will return a number between 0 and 9
if (Timer < Time.time) {
for (var i = 0; i < randNum; i++){
var screenPosition : Vector3 = Camera.main.ScreenToWorldPoint(new Vector3(Random.Range(0,Screen.width), Random.Range(0,Screen.height), Camera.main.farClipPlane/2));
Instantiate(Mines, screenPosition, Quaternion.identity);
Timer = Time.time + 4;
Debug.Log("Spawned Mines");
}
}
}