- Home /
Random.Range HELP!!!
I'm having a problem in javascript and I am still sort of a beginner. I am trying to use Random.Range to make something happen randomly, I am trying to set an int between 0, and 10, but I can't seem to get it right, any advice? Here is my code:
var chance = int(UnityEngine.Random.Range(0, 10));
I get the error: BCE0024: The type 'int' does not have a visible constructor that matches the argument list '(int)'.
Any help would be greatly appreciated!
Answer by aldonaletto · Jun 03, 2013 at 02:17 AM
Don't use int - Random.Range(0, 10) already returns an integer because the parameters are assumed to be integers. Actually, this function will return an integer between 0 and 9 (the last limit isn't included in the range in the integer version):
var chance = Random.Range(0, 10);
Oh ok thanks, I'm new to using Random.Range or the Random function in general, so thank you for explaining!
Answer by Benproductions1 · Jun 03, 2013 at 02:18 AM
Hello,
In Javascript, you cannot call int
. It is a type, not a function. But you can cast to it:
randomInt as int
//or
(int)randomInt
You can also use the Javascript function parseInt
to convert to an integer.
parseInt(randomInt)
Hope this helps,
Benproductions1
ok thanks for the help, Now I think I can get it working!
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How to make a variable equal to Random.Range Result 1 Answer
Code to randomly generate a mesh? 0 Answers
Dreaded UCE0001 ';' error 2 Answers