Today in Ant’s lesson we learned the different C# data types in Unity.
There are 4 main data types we learned about; Integers, Floating points, Booleans, and Strings.
Integers are whole numbers in code, which can be used to do things such as move an asset by a certain amount of pixels/second. In code these variables are written as ‘int’.
Floating points are decimals, which tend to be used in 3D games for things such as rotations. In code these variables are written as ‘float’.
Booleans are usually 2 possible values, where you have one or the other; for example, if you have 1 your character could be classed as alive, whereas 0 is dead (and the game would be over). Booleans are written as ‘bool’ in Unity and as ‘Number’ in Flash.
Strings are chains of characters used to reference something, such as ‘(“Vertical”) in a transform script. Strings are declared in Unity by ‘string’, and by ‘String’ in Flash.
All of these variables can be made available to edit in Unity editor (outside of the script alone) by making them ‘public’ which just comes before the data type. They will then be viewable/editable in the Inspector.
Here are example lines of c# script I wrote to practice writing the different data types.
We then implemented some of this into a space game we have started to make to control the rotation, engine power and thrust of the ship character in the game.
This made the ship accelerate forward when hitting the up arrow key, and rotate clockwise and anticlockwise with the right and left arrow keys.