【发布时间】:2019-10-19 08:50:13
【问题描述】:
我有一个建筑类,我想将它连接到建筑的游戏对象。在课堂上,我有属性:名称、级别、信息。我拥有建筑物的资产(例如农场、城堡、港口)。我有一个游戏类,我在其中创建对象。游戏类是用来存储对象的,所以可以在整个游戏中调用,这样游戏就可以保存和加载了。
我无法通过谷歌搜索找到我想要的东西,我也很难描述我的意思。
建筑类:
[System.Serializable]
public class BuildingObject
{
public string name;
public int level;
public string information;
public BuildingObject(string information)
{
this.name = "";
this.level = 0;
this.information = information;
}
}
这是我创建对象的 Game 类。我希望创建的对象在 GameObject 中被引用,所以我可以通过在其他文件中使用它们来调用某些游戏对象的属性并保持某些游戏对象的级别的进度。
public static Game current;
public BuildingObject church;
public BuildingObject castle;
public BuildingObject fort;
public BuildingObject farm;
public BuildingObject pub;
public BuildingObject houses;
public PlayerObject player;
public StoryObject story;
public Game()
{
church = new BuildingObject("Informatie over de kerk");
castle = new BuildingObject("Informatie over het kasteel");
fort = new BuildingObject("Informatie over het fort");
farm = new BuildingObject("Informatie over de boerderij");
pub = new BuildingObject("Informatie over de kroeg");
houses = new BuildingObject("Informatie over de huizen");
player = new PlayerObject();
story = new StoryObject();
}
我想将 Game 对象中创建的对象连接/引用到相应的 GameObjects。如果我在层次结构中创建了城堡游戏对象,我想要游戏对象中城堡对象的属性。如果有其他更好或更简单的方法,请告诉我,我是 Unity 新手。
【问题讨论】:
标签: c# unity3d gameobject