I'm currently developping turn based RPG game with Unity. For storing Player informations, monsters list and items list, I use static class.
public static class GlobalVariables
{
public static BaseMonster currentMonster;
public static BaseCharacter player;
public static List<BaseMonster> monsterDatabase;
public static Dictionary<string, BaseItem> itemDatabase;
}
I set this values when game loading by json file than use it into all of my scenes.
I wonder if it is harmful like most people' opinions on global variables?
Note: currentMonster is information that set when player selecting monster and Used when "fight scene" loading, to deside what Monster will load.
It's not acutally bad or harmfull, but I would suggest using Singelton: https://en.wikipedia.org/wiki/Singleton_pattern This way you only use one static member. Here is an example as well:https://msdn.microsoft.com/en-us/library/ff650316.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With