c# - Unity中GameObject的引用脚本类
问题描述
我有一个建筑物类,我想将它连接到建筑物的游戏对象。在课堂上,我有属性:名称、级别、信息。我拥有建筑物的资产(例如农场、城堡、港口)。我有一个游戏类,我在其中创建对象。游戏类用于存储对象,因此可以在整个游戏中调用它们,从而可以像这样保存游戏。
我真的无法通过谷歌搜索找到我想要的东西,我也很难描述我的意思。
建筑类:
[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 类。我希望在游戏对象中引用创建的对象,因此我可以通过在其他文件中使用某些游戏对象的属性并保持某些游戏对象的关卡进度来调用某些游戏对象的属性。
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();
}
我想根据 GameObjects 连接/引用 Game 对象中创建的对象。如果我在层次结构中创建了城堡游戏对象,我想要游戏对象中城堡对象的属性。如果有另一种更好或更简单的方法,请告诉我,我是统一的新手。
解决方案
推荐阅读
- ios - 在后台使用 URLSession 和 waitsForConnectivity 执行 Post
- java - 如何在googles checkstyle.xml中的方法之前添加一个标签
- macos - 如何使用终端重新格式化/擦除我的 MAC 内部硬盘
- ios - 如何在快速使用手势识别器选择新视图时从多个视图中取消选择视图?
- .net - 字符映射问题.NET-Informix
- reactjs - 为什么我需要新的 Context API?该值已导入
- python - 在 Windows 10 上安装 Eric6 Python
- angularjs - Button Delete 方法如何首先获取变量数据而不是提示消息?附上我的代码
- java - 访问扩展类中的属性/常量
- c# - 从 WebApi 到 HttpRecquest 中的 Mysql 数据库中检索数据?