Game Development Reference
In-Depth Information
Listing 4: A simple script that interprets presses on the keyboard arrow keys into movement
As we see in Listing 4, player input reading is a continuous process as long as the game
is running. Therefore, we need to handle the input inside Update() function. In lines 16,
20, 24, and 28; we call Input.GetKey() and pass to it a key code to check its state. The
KeyCode enumerator includes codes for all keyboard keys, so we only have to choose the
appropriate one. Input.GetKey() returns true if the given key is pressed during the cur-
Search WWH ::




Custom Search