April 2017
Beginner to intermediate
376 pages
8h 4m
English
Variables are how we store data for use in other places. Now in the preceding example, we want to change the color of an object. Here, we have a piece of code that would do just that:
rend.material.color = new Color(1f, 0.4f, 0.8f);
In this example, we hardcoded a new color; this is considered a bad practice and should be avoided.
To help facilitate this, we use variables; a variable is a name given to space in memory or a storage area. A better way to handle the preceding problem would be to declare a variable and initialize it, or give it a value:
private Color lbColor; lbColor = new Color(0.1f, 0.2f, 0.5f);
Here, the data type is Color and the variable name is lbColor, and we have stored a collection of floats that make a ...
Read now
Unlock full access