Assets \ Scripts \ GameManager.cs(252,23):错误CS0104:“ Random”是“ UnityEngine.Random”和“ System.Random”之间的歧义引用

我正在使用Unity创建蛇游戏,而我有一个方面:

        void RandomlyPlaceApple()
    {
        int ran = Random.Range(0, availableNodes.Count);
        Node n = availableNodes[ran];
        appleObj.transform.position = n.worldPosition;
        appleNode = n;
    }

I've already added using Random = UnityEngine.Random; to the top of my code and no errors appear... but the apple doesn't appear either. I'm thinking something is wrong with my code but I can't find what, can someone please help me out?

编辑:对不起,但是由于某些原因,标签只会让我放unity3d,如果您没有寻找,对不起。

评论
  • 何必太天真
    何必太天真 回复

    您可以从UnityEngine命名空间和System命名空间中获得两个Random类。您可以尝试删除脚本顶部的一个名称空间的导入,也可以仅指定要使用的随机名称。

        int ran = Random.Range(0, availableNodes.Count);
    

    改成

        int ran = UnityEngine.Random.Range(0, availableNodes.Count);