According to many sources online, this is exactly how to make a random number generator using C# in unity 4.6, I even saw one youtube video write it exactly how I did, but it do
You must declare a variable before using it. Declare n
before using it:
int n = 0;
void Start ()
{
n = Random.Range (1, 1000);
print (n);
}
OR
void Start ()
{
int n = Random.Range (1, 1000);
print (n);
}
Now, if you get the error:
'Random' is an ambiguous reference between 'UnityEngine.Random' and 'System.Random'
That's because System
and UnityEngine
are both imported with using System;
and using UnityEngine
Use
UnityEngine.Random.Range(1, 1000);