Marine movement and Camera Control
When we last left the marine, we were learning about transitioning between animation states. Now let's get the marine moving. A full-blown character controller is beyond the scope of this book, but we can still have a lot of fun using the arrow keys for control. The keys we will set up are Up Arrow to move forward, Left Arrow to rotate left, and Right Arrow to rotate right. There's no backing up because marines never retreat!
Here's what to do:
- Drag an instance of your marine prefab into area A of your level layout. For fun, run your game. You should see your marine performing the idle animation.
- Stop the game and open up the
Marine.cs
script in your code editor. - Previously, we had one variable that was a reference to AudioSource. Add these variables below that:
Animator animator; // component ref bool isMoving; public float speed = 3.5f; // walking speed int rotSpeed = 5...