Variables in C# script in unity

There are many variables in unity some of them are usual as we use and some are created by unity API

common variables are

int - all you to store integer value.

float - to store float value

bool - give only true or false value

string -  can store string value

other variable are

GameObject - it is used for accessing gameObject of unity

AudioSource  - using audioSource as a variable

Camera - use camera as a variable

Using variables in Script

you can define variables as
<variable> <name>

defining variables in unity script



Like in above image i have define a public variable of type String that can store string value.
if variable is public then it can be access by other script and value can be change in inspector.
if nothing public or private is not written then it will be private variable.

You can change variable value in inspector after attaching to a gameObject
 
 

When you create a script in unity it will work as a component and as you attach it to a gameObject it will show you all public variables can be edited in inspector

Popular posts from this blog

Positioning GameObjects in unity editor

Creating count down timer in unity by c# script

Changing Image in unity by C# script