Game Development Reference
In-Depth Information
Fig 1.28 The Unity error message displayed when a semicolon is missing from a line of code.
1.5.5 Operators
There are two main types of operators in programming: arithmetic operators
perform mathematical operations between variables and values and relational
operators compare variables and values.
Arithmetic Operators
Basic math operators are shown in Table 1.2 .
The assignment operator you may be more familiar with as an equal sign and
the multiplication and division operators are a little different to those used in
traditional math. Note from the JavaScript examples in Table 1.2 that values
are placed into variables using the assignment operator. To use values already
stored in a variable you simply refer to them in the equations using their
name. It is exactly the same as high school algebra. More complex equations
can also be created, such as
x = (y + z) / 3 + 8;
where parentheses work for order of precedence as they do in traditional
algebra (e.g., the y + z between the parentheses would be calculated first).