User input
The first and relatively simple functionality we can add is the ability to jump. We already have basic physics with gravity working on the Player game object. Before we can make our Player game object jump, we need to know when this should happen. The user always needs some sort of interface in order to interact with the game. On the PC and Mac, in most of cases, it will be the mouse or keyboard. On mobile devices, it will be the touchscreen.
Unity gives us a lot of out-of-the-box functions we can call to check whether user is trying to interact through any input.
As we are writing a standalone game, I think it best if we stick to the mouse control.
Please open the Unity Scripting Reference and search for Input
. You can have a read through the documentation on the Input
class of jump straight to the Input.GetMouseButtonDown
public method. Read it thoroughly.
Input.GetMouseButtonDown
returns true
during the frame when the user pressed the given mouse button. According to the documentation...