Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Unity Game Development Blueprints
  • Toc
  • feedback
Unity Game Development Blueprints

Unity Game Development Blueprints

By : John P. Doran
4 (6)
close
Unity Game Development Blueprints

Unity Game Development Blueprints

4 (6)
By: John P. Doran

Overview of this book

If you want to build enticing projects with Unity, this book is for you. Readers who are familiar with the basics of how to create simple projects in Unity will have an easier time.
Table of Contents (11 chapters)
close
10
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 we've just learned about! Perform the following steps:

  1. Create a new script called 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...
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete