Enemy behavior and AI
The enemy will start with the idle animation as you play the game. Let's add some behavior to the enemy character.
The AI is implemented by creating a pattern, which will determine when the next state change for the enemy will take place, and the period of time that the enemy will either be idle, defend, or attack.
The pattern is an array and has 20 elements in it. After all the elements are exhausted the patterns is randomized and the counter is set to 0 again.
Some intervals last for 10 frames, while others last for up to 120 frames or two seconds. The player has to judge and make sure that he doesn't get hit, and he has to defeat the enemy
before they kill him. This will make more sense once we go through the code.
Create a new C# script and name it enemy
. Add the following script to the code.
First, we initialize our variables:
   using UnityEngine;    using System.Collections;    public class enemy : MonoBehaviour {    private Animator anim;    int myTick...