diffrence between variables

Hello I am a young learner, I am 15 and i am trying to understand the concept of variables. I know how to make them and use them in scripts i do want to know what the diffrence is of:

var

private var

public var

global var

static var

Hi Dr. Light,

A var, as you know, is a variable in javascript.

public vars are ones that are set at the top, outside of all of your functions, that can be seen by other components. These values will also show up in the inspector panel.
**If you just say “var” in your code, it automatically becomes a public var!

private vars are variables that are only important to the script in question and should never be seen by things outside of it. For example, you might have a boolean (true/false) variable called busy. Then, in the Update() function, you could have:

function Update(){
  if(!busy)
    DoSomething()
}

function DoSomething(){
  //This script takes a while, so let's not call it again until we're done.

  busy = true;
  //Something gets done
  // ...
  busy = false;
}

It doesn’t make sense for other scripts to see or change this variable, so it should be kept private.

Global variables are ones that should have the same value for every member of the script. For example, the current level the player is on would be a global variable - every script that needs to know that piece of information should look in the same place, rather than have hundreds of objects each storing their own value. That way, when the level changes you only need to update one value.

In js, to make a global variable you use the keyword static. So static and global are the same thing here.

Note that you can also make functions static. When you do that, you can access that function any time by typing [classname].[functionname] - you don’t need to create a special object first. For example, all the math functions are static functions: Mathf.Sin(angle) calls the Mathf class and looks for the static function Sin().

Good luck!

And when in doubt, Google is a great friend for finding extra information on coding specifics.

~D

Thank you this helped me alot