- Home /
Question by
M2aProductions · Mar 11, 2015 at 09:34 AM ·
timerandom.range
Wait Random Amount of Seconds?
Hello, does anyone know how to make a script where the object does something then waits randomly between ex. 3-6 seconds before doing something else? I know you can use random range, but I don't know how to use it for time.
Comment
Answer by alok-kr-029 · Mar 11, 2015 at 10:09 AM
void Start ()
{
StartCoroutine (waiter());
}
IEnumerator waiter()
{
int wait_time = Random.Range (0, 50);
yield return new WaitForSeconds (wait_time);
print ("I waited for "+ wait_time + "sec");
}
Answer by locky37 · Sep 21, 2021 at 06:05 PM
Unity 2020.3 random conflicts with using System;
Comment //using System;
or UnityEngine.Random.Range();