Making decisions based on user input
Decisions always have to be made when the user provides input. In Chapter 2, Introducing the Building Blocks for Unity Scripts, we used an example where the user had to press the Return/Enter key to call the AddTwoNumbers()
method:
if(Input.GetKeyUp(Keycode.Return)) AddTwoNumbers();
The if
statement condition becomes true only when the Return
key is released after being pressed down. Here's a partial screenshot of the GetKeyUp()
method as shown in the Scripting Reference:
After the Return
key is released, AddTwoNumbers()
is executed.
Note
Notice that the code, AddTwoNumbers()
, isn't between two curly braces. When ...
Get Learning C# by Developing Games with Unity 3D Beginner's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.