I need help figuring out what’s going on. This code was working fine, then I started another script, maybe I changed this one I don’t remember, but now it’s not working. I deleted the new script and put this one back to the best of my ability, but I’m still getting the “NullReferenceException: Object reference not set to an instance of an object” error. The error is on the line with "person.Add(person0) I think. The public GameObjects all have sprites within the inspector. Here’s the code:
public class ChallengesMain : MonoBehaviour
{
public int numOfChallenges;
int challengeNum;
public static List<GameObject> person;
public GameObject person0;
public GameObject person1;
public GameObject person2;
public GameObject person3;
public GameObject person4;
public GameObject person5;
public GameObject person6;
public GameObject person7;
public GameObject person8;
public GameObject person9;
public GameObject person10;
public GameObject person11;
public GameObject dumbLuck;
// Start is called before the first frame update
void Start()
{
System.Random r = new System.Random();
challengeNum = r.Next(0, numOfChallenges);
person.Add(person0);
person.Add(person1);
person.Add(person2);
person.Add(person3);
person.Add(person4);
person.Add(person5);
person.Add(person6);
person.Add(person7);
person.Add(person8);
person.Add(person9);
person.Add(person10);
person.Add(person11);
}