What is a class variable

class variable?
Class?

And how I can recognize the class variable of the Class?

ex: it say Time.deltaTime
Time is the class and deltaTime his class variable.

Parameter? Ex:
function OnCollisionEnter(collisionhit : Collision)
And how I can recognize the class from the parameter?

runtime class?

Thanks

I whish I already know those stuff. :cry:

the class is written in the declaration, in JS following the :
and in C# its the declaration in front of the variable name

A class is simply a group of variables.
A class variable is one of those variables inside a class :slight_smile:

Here’s an example:
Network.Connect();
Network.Disconnect();

Here, Network is the Class, whilst Connect or Disconnect are the class variables.

Think of a class as a class of kids in a school. Each child is a ‘class variable’ :slight_smile:

You really helped him to be totally confused because you don’t have a single variable there, only class functions
Also your explanation lacks the difference between class (static) and object (without static) variables/functions

I would really recommend, that if you have no OO background and don’t want to gain any, you just skip OO completely.
Unity Javascript solves this as you don’t need to know about them. The stuff you need to know is covered in the script reference, the js files themself don’t require any class etc within.

You might want to start with the 2D platformer tutorial to get a better understanding.

If you though want to learn OO and more about classes etc, leave JS behind and take C# because you will find hundreds of tutorials on these topics for C# and also books, both things that are rare to inexistant for unity script as it does not exist outside of unity

Hope this helps… (Untested code!)

class classname //First, define a class!
{
var a = 0;//This young student scored an A in class! :P
var b = "";//setting up variables, just like Vector3.x, this is classname.b
var c : Vector3;
var d = false;
}

var v : classname; //Just like Vector3, you have to define a variable of the class

v.a = 100;// and again, just like saying "myvector.x = 1", v.a = 1 works.
v.b = "Hello World!";
v.c = Vector3(10,20,30);//This is a vector 3! (obviously). Hrrm... a class within a class! :smile:
v.d = true;


var test = "A";
test = addB(test);//Now we get data via a function. test substitutes base in the function

function addB(base)// add b to the end of a string
{
base += "B"; // this takes base (AKA test), and adds b to it!
return base; // we now send the data back to test! When it says "test = addB(test)", it means "test needs to equal what addB returns!"
}

Actually many posts above missed the ‘class’ part.

This is an important distinction because it’s used in the Unity Script Reference.

Note that the above definitions are interchangeable with ‘variable’ and ‘function’. Also note that in the script guide, instance variables are referred to simply as variables.

In this terminology, ‘class variable’ is similar to a ‘static variable’.

The difference is a class variable/function is accessed via the class directly while instance variables (most of those mentioned above) are accessed via an instance of the class.

Examples:

  1. deltaTime is a class variable of Time class so we access it directly from the class:
Time.deltaTime
  1. Find() is a class function of the GameObject class:
GameObject.Find('my name') // OK
  1. GetComponent() is a function (or ‘instance function’) of GameObject so we must access it via an instance of GameObject:
GameObject.GetComponent('SomeScript') // ERROR: Not an instance
obj = Instantiate('SomeObject') // obj is an instance of GameObject
obj.GetComponent(...) // OK

timmer described it well but just more descriptions is more food!!!

classes are descriptions and object are their live representations
i mean there is a class called GameObject and it’s nothing until you create an instance of it.

static variables and static functions (or as unity says class variables and class functions)are variables and functions that they can be accessed without creating an instanc of a clas and normal variables and classes just can be accessed by instances.

about your second question in
variables can reference to a class just like pointers in languages like C/C++ (technically they are not like each other)
for example
in C#
GameObject o;
create a reference variable to a GameObject class called o and
o = new GameObject ();
creates a new instance of GameObject and assign it’s reference to o
and you can access it’s variables and methods by o.??? where ??? is the name of variable or method(function).

hope this helps

What an explanantion!!..Thanks a lot…