How to do it...

We will implement two classes—FormationPattern and FormationManager:

  1. Create the FormationPattern pseudo-abstract class:
using UnityEngine; 
using System.Collections; 
using System.Collections.Generic; 
 
public class FormationPattern: MonoBehaviour 
{ 
    public int numOfSlots; 
    public GameObject leader; 
} 
  1. Implement the Start function:
void Start() 
{ 
    if (leader == null) 
        leader = transform.gameObject; 
} 
  1. Define the function for getting the position for a given slot:
public virtual Vector3 GetSlotLocation(int slotIndex) 
{ 
    return Vector3.zero; 
} 
  1. Define the function for retrieving, if a given number of slots is supported by the formation:
public bool SupportsSlots(int slotCount) 
{ 
    return slotCount <= numOfSlots; 
}
  1. Implement the ...

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.