c# - Unity 在编译有效的 C# 类时遇到问题

我现在正在开发一个简单的游戏,Unity 给了我一个奇怪的错误。我有一个名为 Level 的 C# 类它有一个带有四个参数的构造函数:

using System;

namespace World
{
    public class Level
    {
        public Grid grid { get; private set; }
        public int starty { get; private set; }
        public int endy { get; private set; }

        public Level(int width, int height, int starty, int endy)
        {
            this.grid = new Grid(width, height);
            this.starty = starty;
            this.endy = endy;
        }
    }
}

还有一个名为 WorldGen 的类这仍然没什么:
using System;
using World;

namespace WorldGen
{
    public class WorldGen
    {
        public Level GenerateLevel(int width, int height, int starty, int endy)
        {
            Level level = new Level(width, height, starty, endy); // Line 47

            Grid grid = level.grid; // Line 49

            // ...

            return level;
        }
    }
}

这对我来说真的很简单,(并且在项目的任何地方都没有调用 GenerateLevel)。调用csc在 PowerShell 中编译目录中的所有文件,没有任何错误或警告。

但是在 Unity 窗口中,我遇到了对我来说没有多大意义的错误:

Assets/WorldGen/WorldGen.cs(47:65): error CS1729: The type 'Level' does not contain a constructor that takes '4' arguments Assets/WorldGen/WorldGen.cs(49:31): error CS1061: The type 'Level' does not contain a definition for ''grid' and no extension method 'grid' of type 'Level' can be found (are you missing a using directive of an assembly reference?)



就像 WorldGen可以访问类 Level但看不到它的任何公共(public)方法。

在我看来,Unity 对我的代码似乎是错误的,但从经验来看,这种情况很少见。我只是不知道它想从我这里得到什么。 Level在项目目录中。它的构造函数有 4 个参数,我将它需要的类型传递给它,它具有公共(public) grid field 。让我明白的是,当从图片中删除统一时,我知道这段代码会自行编译。

我不知道我错过了什么,我想知道是否有人可以给我一个线索。

最佳答案

我会说你与Level有命名冲突。尝试明确指定命名空间:
World.Level level = new World.Level(width, height, starty, endy);

https://stackoverflow.com/questions/29856471/

相关文章:

jsf - ServletContext.TEMPDIR无法解析或不是字段

compiler-errors - e编译错误数

compiler-errors - ifort composer_xe_2015.3.187的编译问

compilation - 在Cygwin上编译GRUB(64位)

asp.net - 错误: SignalRRouteExtension.Mapconnection

compiler-errors - 在Solaris Sparc 11下强制使用Sun Studio

c# - 类数组使用产生错误 "NullReferenceException: Object ref

scala - 使用 Deadbolt 2 : overriding method getSubje

compiler-errors - 由于 glib 错误,无法处理 gobject-introspe

scala - 在scala中的构造函数内部调用函数