Hey
I want to declare “global” variables on a script. What do i mean by “global”? A variable that i declare on a script but i can use in any other script.
Also, how can i declare variables and keep them when changing scenes?
Put static keyword in front of variable and make it public. Then use Class.staticVarName to acess variable. Static vars are ‘saved’ between scenes.
Use static. But generally be aware global variables are often a very bad idea.
This is not global, this is simply public.
https://unity3d.com/learn/tutorials/topics/scripting/persistence-saving-and-loading-data
Why are they a bad idea?
I have a GameObject that runs a script on start that defines all the clothing the current character is wearing, and when we go to the next scene all the clothing is retrieved from the global variables and applied to the real character. Is there a better way to do that? Should i use the PlayerPrefs for it?
Also, what variable type should i use to make a script that loads all clothing available into memory when the game starts? I’m using static arrays for that