What does it mean by object reference is not set to an instance of an object
Edit: the errors on line 24
using System.Reflection.Emit;
using Unity.VisualScripting;
using UnityEngine;
public class Generation : MonoBehaviour
{
public GameObject room;
private int currentroomXPos = 0;
private int currentroomYPos = 0;
int Direction;
private int [] Xarays;
private int [] Yarrays;
int k = 0;
public void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Player")
{
generateRoom();
}
}
private void generateRoom()
{
start:
for (int i = 0; i < Xarays.Length; i++)
{
if (currentroomXPos != Xarays[i] && currentroomYPos != Yarrays[i])
{
Instantiate(room, new Vector3(room.transform.position.x + currentroomXPos,0,room.transform.position.y + currentroomYPos), Quaternion.identity);
Xarays[Xarays.Length] = currentroomXPos;
Yarrays[Yarrays.Length] = currentroomYPos;
}
else
{
k++;
}
}
if (k == Xarays.Length)
{
k = 0;
goto start;
}
else
{
k = 0;
}
Direction = Random.Range(1, 4);
if (Direction == 1)
{
currentroomXPos += 10;
}
if (Direction == 2)
{
currentroomXPos -= 10;
}
if (Direction == 3)
{
currentroomYPos += 10;
}
if (Direction == 4)
{
currentroomYPos -= 10;
}
}
}