I’ve heard that “var” assigns variables (of course) and if you don’t write it, it’ll become a global variable so you could write it in different scripts. Is this true? (I learn’t a lot of scripting in a bunch of tutorials, but these tutorials didn’t really say if you needed the var, they just said just put it there)
Nvm found that static is for global.
Just adding to this.
It is a point of confusion for me to.
I thought all variables were global unless delcared private and static was a special type where you could only have one.
However I can only get the global to work with static?
There’s no “global” (closest is Unity misnomers “static” as “global”)
“var” just declares a new variable.
“public” means its accessible to all other scripts.
“private” means its accessible only to the script it belongs to.
“static” (or Unity’s version of “global”) means it can be accessed without being attached to an instance of an object (it belongs to the type/script, not to an object/GameObject)
If there’s no “static”, it means it belongs to an instance of an object and you must obtain a reference to that object (say via GetComponent) to use it.
You can combine some of them, for example “private static” means it employs the static concept but only accessible for that particular script type. “public static” means its accessible to all scripts.