0

Недавно столкнулся с ошибкой "NullReferenceException: Object reference not set to an instance of an object" Можете помочь поправить, ума не приложу?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class test2 : MonoBehaviour
{
    public List<test> tests;
    // Start is called before the first frame update
    void Start()
    {
        tests.Add(new test());
        tests[0].ints.Add(123);
    }
    [System.Serializable]
    public class test
        {
        public List<int> ints;
    }
}

1 Answers1

0

У вас неинициализированный список ints в вашем классе.

[System.Serializable]
public class test
{
    public List<int> ints = new List<int>();
}
Alex Krass
  • 17,744