- Home /
Random number on game start for a variable
Ok so I have the variable
public int m_ground = 0;
and I need that 0 to be a random whole number from 0-20. Ideas?
Answer by amphoterik · Jul 16, 2013 at 05:15 PM
you would do:
m_ground = Random.Range(0, 20);
http://docs.unity3d.com/Documentation/ScriptReference/Random.Range.html
If this answered your question, please select it as the correct answer. This will help future readers and give you karma.
@clunk47 not true. Random.Range is inclusive. What I gave works 0-20
@clunk47 ah, you are correct. I just saw where it labeled them as [inclusive] at the top of the page. Strange way to say that.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Random.Range produces 2 numbers for me? 1 Answer
How to write "if (var int = var int 2)" ? 1 Answer
Picking one of two numbers. 1 Answer
How to randomly generate prefab? 2 Answers