Trying to make a random number generator in C# unity 4.69

前端 未结 1 1076
被撕碎了的回忆
被撕碎了的回忆 2021-01-29 10:39

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

1条回答
  •  离开以前
    2021-01-29 11:09

    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 UnityEngineUse

    UnityEngine.Random.Range(1, 1000);
    

    0 讨论(0)
提交回复
热议问题