class World
{
bool _playerHasWonGame = false;
public void Update()
{
Entity player = FindEntity("Player"); //ERROR: The type or namespace name 'Entity' could not be found(are you missing a using directive for an assembly reference?)
}
private Entity FindEntity(string p) //Same ERROR
{
throw new NotImplementedException();
}
}
class Inventory
{
public bool Contains(Entity entity)
{
return false;
}
}
public class Entity
{
public Inventory Inventory { get; set; }
}
错误部分是实体。
我创建了实体类,并尝试在世界类中制作实体对象。
据我了解,它应该有效。我只是尝试像其他 C# 程序员一样制作对象。但是,看起来我的编译器找不到实体定义。
默认情况下,
类不是公共的,因此Inventory
比返回其实例的属性更难访问。
要么将Entity
更改为内部的(因此它及其属性将存在于与Inventory
相同的范围内),要么Inventory
公开。
(通过任一更改代码片段为我编译)