Variables

Kinga Osińska
2 min readApr 2, 2021

Variables are containers for storing data values.

How to create a variable?

  • First, you need to decide if you want your variable to be public or private

public — you can access this variable from other components, scripts, or in the Inspector.

private — you have access to this variable only in the script it is declared in.

If you don’t need to access a variable by another script, then that variable should be private.

What type of variable you need.

Few examples of data types:

Name of your variable

To name your variable, we use what’s called CamelCasing. It means that the first letter of each word is capitalized, except for the first word.

You should name your private fields with an underscore prefix.

Initializing Variables (optional)

You can assign a value to your variable when you define its type, or you can do this later in your code.

--

--