Game Development Reference
In-Depth Information
transform.TransformDirection (-Vector3.up) *
distance);
Gizmos.DrawRay(leftOrigin,
transform.TransformDirection (-Vector3.up) *
distance);
}
10. Now, save it and go back to Unity; drag-and-drop the
PlayerController_2D
script to
Player
, click on
Player
, and go to the
Inspector
window. Click on
Idle
Sprite
and
Walk Sprite
to expand it and then set the following:
Player Controller_2D (Script)
Door Open Sound
doorOpen
Get Key Sound
getkey
Jump Sound
jump
Layer Mask
Ground
Yes! We are done. Let's click on the
Play
button to play the game. We will see our player
moving his hand back and forth. Next, press the
A
or left arrow /
D
or right arrow to move
the player to the left or to the right; now we see that he is walking. We can also press the
Space bar to make our character jump. Isn't that cool?