what's the differents between capital & small

Hi.. I'm new in unity

I saw a lot of examples about the scripts in Unity . but so far I didn't understand what the different between the word that start with capital letter and the other that start with small letter

example :

var target : trasnform;

var target : Transform;

GameObject OR gameObject

Rigidbody OR rigidbody

when we have to right the word with capital letter and when small

thanks..

2 Answers

2

Correct m e if I'm wrong.

But I think with capital letters GameObject it's a class, and with small letter gameObject it's a component/mehtod.

It's the convention used in Unity, but it doesn't hold true everywhere. But for a beginner coder it's sufficient to go with this idea and not get too involved with whats under the surface yet. All this will become clear eventually, just take a bit at a time.

You use a lower case letter when reffering to a component of the object that the script is attached to. So for example if we have a script called BasicScript.js and we attach it to a cube object. We use:

transform.Translate(Vector3.up);

By using the lower case "transform" we are basically saying "this objects transform".The same goes for gameObject. We use capitals when we are declaring a new object or reffering to an object not that is not attached to the script.

In your examples; transform is a variable. Transform is a type. gameObject is a variable. GameObject is a type. rigidbody is a variable. Rigidbody is a type.

You'll notice that the .net/mono framework use a different convention, where all public members are capitalized. like array.Length. You just need to learn the differences about which are variables and which are types. Just saying that types are capitalized and variables aren't is not enough.