In my tile script I have the following line: “int[,] map = new int[20,20];”. In Start(); I do the following:
int[,] map = {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,2,2,1},
{1,1,1,1,1,1,3,3,3,3,1,1,1,3,3,3,3,2,2,1},
{1,3,1,1,1,1,3,3,3,3,1,1,1,1,3,3,2,2,3,1},
{1,3,3,1,1,1,3,3,3,3,3,3,3,3,3,3,2,2,3,1},
{1,3,3,3,1,1,3,3,3,3,3,3,3,3,3,2,2,3,3,1},
{1,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,3,3,3,1},
{1,3,3,3,1,1,3,3,3,3,3,3,3,2,2,3,3,3,3,1},
{1,3,3,1,1,1,3,3,3,3,3,3,2,2,3,3,3,3,3,1},
{1,3,3,1,1,1,3,3,3,3,3,3,2,2,3,3,1,1,3,1},
{1,1,1,1,1,1,3,3,3,3,3,3,2,2,3,3,1,1,3,1},
{1,1,1,1,1,3,3,3,3,3,3,3,2,2,3,3,1,1,3,1},
{1,3,3,3,3,3,3,3,3,3,3,3,2,2,3,3,1,1,3,1},
{1,3,3,3,3,3,2,2,2,4,2,2,2,3,3,1,1,1,1,1},
{1,3,3,3,3,2,2,2,2,4,2,2,3,3,3,1,1,1,1,1},
{1,3,3,3,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,1},
{1,3,3,2,2,3,3,3,3,3,1,1,1,1,1,3,3,3,3,1},
{1,3,2,2,3,3,3,3,3,3,1,1,1,1,1,3,3,3,3,1},
{1,2,2,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
At the bottom of my script I have a function
public int GetTileAt(int x, int y)
{
int value = map[y,x];
return value;
}
When I access this function from a different script the return value is 0. If I do the follow from within the function
foreach(int tile in map)
{
Debug.Log(tile);
}
The Debug.Log says 400 0’s. Why is this? Is it a scope issue?