I have a class for a building and I want to connect it to a game object of a building. In the class, I have the properties: name, level, information. I have an asset of the buildings (things like farm, castle, harbor). I have a Game class where I create the objects. The game class is used to store the objects, so they can be called through the entire game and so that the game can be saved an loaded like this.
I can't really find what I want by Googling, I also find it hard to describe what I mean.
The Building class:
[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;
}
}
This is the Game class where I create the objects. I want the created objects to be referenced inside a GameObject, so I can call properties of certain gameObjects by using them in other files and keeping progress of the level of certain 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();
}
I want to connect/reference the created objects inside the Game object to according GameObjects. If I have created a castle GameObject in the hierarchy, I want the properties of the castle Object inside the GameObject. If there is another better or easier way, please let me know, I am new to unity.