We will create the Waypoint class and add the methods for condensing the set of waypoints:
- Create the Waypoint class, deriving from both MonoBehaviour and from the IComparer interface:
using UnityEngine;using System.Collections;using System.Collections.Generic;public class Waypoint : MonoBehaviour, IComparer{ public float value; public List<Waypoint> neighbours;}
- Implement the Compare function from the interface:
public int Compare(object a, object b){ Waypoint wa = (Waypoint)a; Waypoint wb = (Waypoint)b; if (wa.value == wb.value) return 0; if (wa.value < wb.value) return -1; return 1;}
- Implement the static function that checks whether an agent is able to reach one waypoint from the other:
public static bool CanMove(Waypoint ...