- Home /
ArgumentException: RandomRangeInt can only be called from the main thread.
I am getting this compile error when I try and run this script: RandomRangeInt can only be called from the main thread.
private var random = Random.Range(0, 4);
function Update ()
{
print (random);
}
Any Idea on how to solve this??
--Thanks!
Answer by Tasarran · Jan 10, 2012 at 05:47 AM
Yeah, don't try to run that Random command on variable init, do it this way:
private var random : int;
function Start ()
{
random = Random.Range(0, 4);
}
function Update ()
{
print (random);
}
If you want it to continuously make new random numbers, put that line from Start into Update also.
But if your going with a higher Random.Range to decide when your event is triggered then keeping "waitTime = Random.Range(55, 650);" or whatever inside the update will that not update the value to a new value every frame thus never calling the event?
Your answer
Follow this Question
Related Questions
Generate 8 unique random integers 2 Answers
Random Number Generator 4 Answers
Random texture changer (problem with array) 2 Answers
RNG output to a variable + instantiating a prefab based on said variable? 1 Answer
Minecraft In Unity, Coal and Iron 1 Answer