Game Development Reference
In-Depth Information
57.}
Listing 8: Reading mouse input
Let's discuss the important parts of this script. First of all we have the movement speed
in line 7, in addition to three variables of type Color in lines 10 through 12. These vari-
ables are able to store a specific color, which can be either picked from the color palette
in the inspector, or set directly from code just like what we do here. In line 15, we define
lastMousePosition variable, which is going to hold the last position of mouse pointer and
allow us to compute mouse displacement every frame update. At the beginning of the ex-
ecution (line 23), we set lastMousePosition to the current position of the mouse, which we
get from Input.mousePosition . By doing this, we guarantee that the displacement is going
to be zero when the first frame is rendered.
Search WWH ::




Custom Search