How to store the information of objects

Hi everyone,

I have watched some officials tutorials but I still dont get how I should store the information in my game.

In the game that I am trying to develope I want that the user will be able to create and manage some buildings (GameObjects). That buildings have some characteristics depending on the building type and the building level.

All the buildings with same ID and same level have the same characterisitcs or attributes. The characteristics are not edited during the game.

Are there any way to query the attributes of that ID and level like a table?

I know that I can try to get it by creating a class called buildings with a bunch of switch-case but I think that it shouldnt be the best way.

What would you do to manage that?

Sorry if my English is not good. Not my mother tongue.

Thak you.

[PlayerPrefs][1] are by far not the only solution, but they are easy to use and to get into.

The gist is: You save simple values with the SetXY functions and retrieve values with the GetXY functions. Between saving and loading, the game is allowed to be closed as the information is stored permanently.

The PlayerPrefs class is pretty simple. You can store numbers and strings with it using string keys - and that’s it. This means that if you want to save complex data, you need to develop a bit of extra code around it. That is one of the reasons why with growing savegame complexity, people tend to, at some point, drop PlayerPrefs for something else.

For example, to implement a List saving function, you could write this:

public static void SetIntList(string key, List<int> value)
{
  PlayerPrefs.SetInt(key + ".Count", value.Count);
  int i;
  for(i = 0; i < value.Count; i++)
  {
    PlayerPrefs.SetInt(key + "[" + i + "]", valie*)*

}
// Now delete all list items from previous saves
for(; PlayerPrefs.HasKey(key + “[” + i + “]”); i++)
{
PlayerPrefs.DeleteKey(key + “[” + i + “]”);
}
}
It’s up to you to decide whether you build upon PlayerPrefs or any other system, like storing XML files or the like in your [Application.persistentDataPath][2].
[1]: Unity - Scripting API: PlayerPrefs
[2]: Unity - Scripting API: Application.persistentDataPath

Use XML files.
Create an XML file and add all your various building type with all their levels. You can retrieve and add any information you want.