Hello Guys,
I am stuck about how to do well things arround Json.
I have a static class to store my character datas (name, attaque, level etc.)
I have a class to load JSON datas coming from a php script.
My problem is to store my json datas into a static class to keep it during all the game, but I can’t make it directly
Global Class for all project :
public class GlobalVar {
public static CharacterJson characterJson = new CharacterJson();
}
My Character class, that is not a static one to load easly from JSON
[System.Serializable]
public class CharacterJson {
public string name;
public int attaque;
public int level;
}
JSON load correctly my datas
GlobalVar.characterJson = JsonUtility.FromJson<CharacterJson>(JsonDataFromServer);
info.text = GlobalVar.characterJson.name;
info.text display the data correctly, but when i will use my Character class elswhere i got a Null.that’s why i am looking to store my Json directly in a static Character class.
I dont want to create a “copy” static class to pass data. like :
public static class Character {
public static string name;
public static int attaque;
public static int level;
}
I want to avoid a thing like that in my script, especialy if i must to change my Character class to add more datas.
Character.name = GlobalVar.characterJson.name;
Character.attaque = GlobalVar.characterJson.attaque;
Character.level = GlobalVar.characterJson.level;
I need to know how to put my datas from Json directly in my static class.
Well i hope i am clear enought.
Cheers