I came up with a different way to do what Gary did in the lecture that I think is pretty good. It differs in that Gary made a reference variable using the dictionary (did I say that right?) and searched using a key, whereas I used the GetNode() method through the gridManager reference made earlier. Why would someone choose one way versus the other? Does it matter much at all? My code is below; thanks for your time in helping me understand.
P.S. There seems to be some weirdness of the formatting of my code, sorry if it’s difficult to read.
>
> using System.Collections;
> using System.Collections.Generic;
> using UnityEngine;
>
> public class PathFinder : MonoBehaviour
> {
> [SerializeField] Node currentSearchNode;
> Vector2Int[ ] directions = { Vector2Int.right, Vector2Int.left, Vector2Int.down, Vector2Int.up };
> GridManager gridManager;
> //Dictionary<Vector2Int, Node> grid = new Dictionary<Vector2Int, Node>();
> private void Awake()
> {
> gridManager = FindObjectOfType<GridManager>();
>
>
> }
> void Start()
> {
> ExploreNeighbors();
> }
>
> void ExploreNeighbors()
> {
>
> List<Node> neighbors = new List<Node>();
>
>
> foreach (Vector2Int direction in directions)
> {
> Vector2Int neighborCoordinates = currentSearchNode.coordinates + direction;
>
> if (gridManager.GetNode(neighborCoordinates) != null)
> {
> Node nodeToBeAdded = gridManager.GetNode(neighborCoordinates);
> neighbors.Add(nodeToBeAdded);
>
> //TODO: Remove after testing
> nodeToBeAdded.isExplored = true;
> nodeToBeAdded.isPath = true;
> }
>
> }
>
> }
>
>
> }