Getting ready

Before implementing the fighting circle algorithm, it is important to create some components that accompany the technique. First, the Attack class is a pseudo-abstract class for creating general-purpose attacks for each enemy, and it works as a template for the custom attacks in our game. Second, we need the Enemy class, which is the holder of the enemy's logic and requests. As we will see, the Enemy class holds a list of the different attack components found in the game object.

The code for the Attack class is as follows:

using UnityEngine; 
using System.Collections; 
 
public class Attack : MonoBehaviour 
{ 
    public int weight; 
 
    public virtual IEnumerator Execute() 
    { 
        // your attack behaviour here 
        yield break; 
    } 
}

The steps to build ...

Get Unity 2018 Artificial Intelligence Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.