【问题标题】:Why I cant use Random.Range code system on Unity 2D为什么我不能在 Unity 2D 上使用 Random.Range 代码系统
【发布时间】:2020-11-08 10:52:11
【问题描述】:

我在统一 2D 中使用此代码:

    float nilaiRandom;
    void Start()
    {
        nilaiRandom = Random.Range(1.11f, -1.88f);
        transform.position = new Vector2(transform.position.x, nilaiRandom);
    }

Unity 计数错误它说:Assets\Go.cs(14,23): error CS0104: 'Random' is an ambiguous reference between 'UnityEngine.Random' and 'System.Random' 我的团结到底发生了什么,解决方案是什么?请帮帮我

【问题讨论】:

    标签: c# unity3d random


    【解决方案1】:

    .Net 带有 System.Random,而 Unity 带有 UnityEngine.Random。如果您同时拥有using Systemusing UnityEngine,则它们之间存在歧义。限定名称以消除歧义:

    UnityEngine.Random.Range(1.11f, -1.88f);
    

    【讨论】:

    • @Mr.Aby 如果它解决了您的问题,请考虑接受答案,这样您的问题就不会没有答案。
    • 我的错,我刚接触堆栈溢出
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多