Creating good waypoints
There are times when the number of waypoints must be reduced at a certain point during the game or just for memory constraints. In this recipe, we will learn a technique called condensation that helps us deal with this problem, forcing the waypoints to compete with each other given their assigned value.
Getting ready
In this recipe, we will deal with static member functions. It is important that we understand the use and value of static functions.
How to do it…
We will create the Waypoint class and add the functions for condensing the set of waypoints.
Create the
Waypointclass, deriving not only fromMonoBehaviour, but also from theIComparerinterface:using UnityEngine; using System.Collections; using System.Collections.Generic; public class Waypoint : MonoBehaviour, IComparer { public float value; public List<Waypoint> neighbours; }Implement the
Comparefunction from the aforementioned interface:public int Compare(object a, object b) { Waypoint wa...