the class that I've made:
public class singleWeeklyWorking_Period
{ // this class holds a single period of work schedule, that can appear weekly on specific days
public bool[] onDays = new bool[7]; // 7 days a week, set to true on days that this period appears
public int startTime = 0; // in minutes
public int endTime = 0;
public void show() // just for testing
{
UnityEngine.Debug.Log("days: " + onDays[0] + ", "+ onDays[1] + ", "+ onDays[2] + ", "+ onDays[3] + ", "+ onDays[4] + ", "+ onDays[5] + ", "+ onDays[6]);
UnityEngine.Debug.Log("startTime: " + startTime);
UnityEngine.Debug.Log("endTime: " + endTime);
}
}
the code that uses the class (just for testing):
public List<singleWeeklyWorking_Period> listOfWeeklyWorkingTime ;
// lists of working time
// Start is called before the first frame update
void Start()
{
singleWeeklyWorking_Period period = new singleWeeklyWorking_Period();
period.onDays[0] = true;
period.startTime = 60;
period.endTime = 120;
listOfWeeklyWorkingTime.Add(period);
listOfWeeklyWorkingTime[0].show();
}
as you can see in "singleWeeklyWorking_Period period = new singleWeeklyWorking_Period();". I instantiated the class. but it still gives me an error that says:
NullReferenceException: Object reference not set to an instance of an object
is it the variable inside the class? but I've set it just before I add it to the list:
period.onDays[0] = true;
period.startTime = 60;
period.endTime = 120;
I'm quite confused, all the help is appreciated!