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:

Making decisions based on user input

After the Return key is released, AddTwoNumbers() is executed.

Note

Notice that the code, AddTwoNumbers(), isn't between two curly braces. When there is only one line of code to execute for an if or an else, you have the option to not use the curly braces.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.198.59