A variable is like a storage box. You can name the box, definite the type, give the data, and take out whenever you want.
Variables can be used in many ways depend on the type.
There are 4 common variables in Unity:
string: for containing text or sentence.
int: for integer
float: for float numbers
bool: for boolean
To declare a variable in Unity, we need to make sure whether is
public or not, then given a name.
public variable is public to everything, unlike
private can only be used in its own script. You need to add
private at the beginning of a variable, or it will be private by default.
public variable can also let you easily to adjust in the Inspector when attached to a game object.
To naming a variable, always follow the rule called camelCase.
A camelCase is to set the first letter of each word in a compound word is capitalized, except for the first word.
You can use variables to do some calculation.
If you want to combine
float, make sure declare a
float as result to prevent occur an error.
You can also make complex calculation in one line.