Hi all, I’m newish to unity and C#, but this is the first issue I’ve run into that has really stumped me. I’m currently writing code to highlight all tiles within a unit’s movement range, but I’m getting an error that claims that an array (int[,] tilesHighlighted) does not exist in the context of a function, despite it being declared globally.
public class rangeHandler : MonoBehaviour
{
public tileMap map = new tileMap();
public tileData td = new tileData();
int[,] tilesHighlighted;
public void showRange(int x, int y, int r)
{
tilesHighlighted[map.graph[x, y].x, map.graph[x,y].y]
= map.tileAtNode(map.graph[x, y].x, map.graph[x, y].y);
foreach (Node n in map.graph[x, y].edges)
{
if (tilesHighlighted(n.x,n.y) == null)
{
tilesHightlighted[n.x, n.y] = map.tileAtNode[n.x, n.y];
}
}
r--;
}
Everywhere past “foreach”, it’s giving me an error. Its first usage at the beginning of showRange() is fine. Any ideas?