Error: NullReferenceException: Object reference not set to an instance of an object.
Board.gemsSpawn (UnityEngine.Vector2Int pos, Gems gemsTospawn) (at Assets/my assets/scripts/Board.cs:45)
Board.Setup () (at Assets/my assets/scripts/Board.cs:34)
Board.Start () (at Assets/my assets/scripts/Board.cs:18)
code
public class Board : MonoBehaviour
{
public int width;
public int height;
public GameObject BgtilesPrefab;
public Gems[] gems;
public Gems[,] allGems;
// Start is called before the first frame update
void Start()
{
Setup();//***** line 18
allGems = new Gems[width, height];
}
private void Setup()
{
for(int x = 0; x < width; x++)
{
for(int y= 0; y < height; y++)
{
Vector2 pos = new Vector2(x,y);
GameObject bgtiles = Instantiate(BgtilesPrefab, pos, Quaternion.identity);
bgtiles.transform.parent = transform;
bgtiles.name = “Tile NO-” + x + “,” + y;
int gemTouse = Random.Range(0, gems.Length);
gemsSpawn(new Vector2Int(x, y), gems[gemTouse]);//*****line43
}
}
}
private void gemsSpawn(Vector2Int pos, Gems gemsTospawn)
{
Gems gem = Instantiate(gemsTospawn, new Vector3(pos.x,pos.y,0f), Quaternion.identity);
gem.transform.parent = transform;
gem.name = "Gem-" + pos.x + "," + pos.y;
allGems[pos.x, pos.y] = gem;//******line 45
gem.setupgems(pos,this);
}
}