我现在正在开发一个简单的游戏,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;
}
}
}
csc
在 PowerShell 中编译目录中的所有文件,没有任何错误或警告。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)方法。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 - 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