What is public var?

I know var and static var

but what is public var and other place’s public means?

public means that other scripts can access it and private means tat only the script where it resided can access it.

Are there any thing different about public vars and static ones. :smile:

For JavaScript, I’m not knowledgeable enough. I know C# better and even there I’m still learning but here’s a go…

a static variable can be accessed globally without you having to instantiate the class.

So you can call it like so.

ClassName.NameofStaticvariable.

While a public variable, the class needs to be instantiated first with in the class you want to use it.

Example C#;

private ClassName className;

private void start()
{
className = new ClassName;

string localVariable = className.publicVariable;
}

Hope this clarifies.

Also (from memory), protected means that it can only be accessed by that class, and other classes that inherit from that class.

When you say, “you know var”, that’s already a public variable. In C#, you have to explicitly use the word public, but it’s implied in Unity’s JavaScript. Public variables by default, in JavaScript, have these attributes:

Declared using “var”, not “private var”, etc.
Can be accessed from other scripts as shown in part #1.
Show up in the Editor as editable fields.
Are serialized (saved with the Scene.)

So, what would be the point?