I can’t understand this script, mostly the exploreneighbors method, could someone explain me?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PathFinder : MonoBehaviour
{
[SerializeField] Node currentSearchNode;
Vector2Int[] directions = {Vector2Int.right, Vector2Int.left, Vector2Int.up, Vector2Int.down };
GridManager gridManager;
Dictionary<Vector2Int, Node> grid;
private void Awake()
{
gridManager = FindObjectOfType<GridManager>();
if (gridManager != null)
{
grid = gridManager.Grid;
}
}
void Start()
{
ExploreNeighbors();
}
void ExploreNeighbors()
{
List<Node> neighbors = new List<Node>();
foreach(Vector2Int direction in directions)
{
Vector2Int neighborsCords = currentSearchNode.coordinates + direction;
if (grid.ContainsKey(neighborsCords))
{
neighbors.Add(grid[neighborsCords]);
//to do: remove after testing
grid[neighborsCords].isExplored = true;
grid[currentSearchNode.coordinates].isPath = true;
}
}
}
}