Hey guys, whenever I try to give 2Darray/matrix value I get this error: NullReferenceException: Object reference not set to an instance of an object
Here is the code:
using UnityEngine;
using System.Collections;
public class genTerrain2 : MonoBehaviour {
public int[][] qGrid;
public int[][] rGrid;
public int range = 1; //Size of map
void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
for (int q = -range; q != range+1; q++)
{
for (int r = -range; r != range+1; r++)
{
qGrid[q+range][r+range] = q;
rGrid[q+range][r+range] = r;
}
}
}
}
}
I get an error in “qGrid[q+range][r+range] = q;
” and “rGrid[q+range][r+range] = r;
” lines.
Thanks in advance!