Book Image

Unity 5.x Game Development Blueprints

By : John P. Doran
Book Image

Unity 5.x Game Development Blueprints

By: John P. Doran

Overview of this book

<p>This book will help you to create exciting and interactive games from scratch with the Unity game development platform. We will build 7-8 action-packed games of different difficulty levels, and we’ll show you how to leverage the intuitive workflow tools and state of the art Unity rendering engine to build and deploy mobile desktop as well as console games.</p> <p>Through this book, you’ll develop a complete skillset with the Unity toolset. Using the powerful C# language, we’ll create game-specific characters and game environments. Each project will focus on key Unity features as well as game strategy development. This book is the ideal guide to help your transition from an application developer to a full-fledged Unity game developer</p>
Table of Contents (19 chapters)
Unity 5.x Game Development Blueprints
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface
Index

Enemy movement


As spooky as the character is, right now, it is just a static mesh. It will not come to us to damage us, and we cannot damage it. Let's fix that next using the state machines you've just learned about! Perform the following steps:

  1. Create a new script named EnemyBehaviour.

    We want our enemy to follow the player if they get too close to them; however, they will stay where they are if the player gets far enough away. Finally, if, for some reason, we defeat the enemy, they should no longer run this behavior, and we should kill them. The first step to creating a state machine is to extract the states that the object can be in. In this case, we have three states: Idle, Following, and Death. Just as we discussed in Chapter 2, Creating GUIs, using an enumeration is the best tool for the job here as well.

  2. Add the following code to the top of the EnemyBehaviour class:

       public enum State 
      {
        Idle,
        Follow,
        Die,
      }
    
       // The current state the player is in
      public State state...