public class PathFinder : MonoBehaviour {
Dictionary<Vector2Int, Waypoint> grid = new Dictionary<Vector2Int, Waypoint>();
[SerializeField] Component startBlock;
[SerializeField] Component endBlock;
// Use this for initialization
void Start () {
LoadBlocks();
}
private void LoadBlocks()
{
var waypoints = FindObjectsOfType<Waypoint>();
foreach (Waypoint waypoint in waypoints){
// overlapping
// add to dictionary
bool isOverlapping = grid.ContainsKey(waypoint.GetGridPos());
if (isOverlapping){
Debug.LogWarning("Overlapping block: " + waypoint.GetGridPos());
}
else {
ColourTop(waypoint);
grid.Add(waypoint.GetGridPos(), waypoint);
}
}
}
private void ColourTop(Waypoint waypoint){
if (waypoint.transform.Find("Top") == startBlock.transform.Find("Top"))
{
waypoint.SetTopColour(Color.green);
print("Start cube found");
}
else if (waypoint.transform.Find("Top") == endBlock.transform.Find("Top"))
{
waypoint.SetTopColour(Color.red);
print("End cube found");
}
else
{
waypoint.SetTopColour(Color.blue);
}
}
So I carried on with where we were and coloured them appropriately as they were found by the path finder. I don’t think it will make a difference overall since we’re simply establishing them in the inspector anyway. Where my code will likely fall down later on is because I added them as Component type rather than Waypoint type. So I’ll modify it to that now and see how I get one going forward.