Question by
awesumenes · Aug 19, 2019 at 11:40 PM ·
objectlistnullreferenceexceptionclasses
NullReferenceException : Object reference not set to an instance of an object?
Hello, I'm trying to create a list of objects that hold information about the different types of bosses in y game but I keep getting this error when the list is trying to add an object from the Bosses class to the list.
Bosses Class:
public class Bosses
{
Sprite bossSprite;
float Highscore;
float[] timeReq;
int[] WA;
public Bosses(Sprite bossSprite, float Highscore, float[] timeReq, int[] WA)
{
this.bossSprite = bossSprite;
this.Highscore = Highscore;
this.timeReq = timeReq;
this.WA = WA;
}
public int[] getWARatio()
{
return WA;
}
public Sprite getSprite()
{
return bossSprite;
}
public float getHighscore()
{
return Highscore;
}
public float[] getTimeReq()
{
return timeReq;
}
public Bosses getInstance()
{
return this;
}
}
BossInfo Class:
public class LevelInfo : MonoBehaviour
{
List<Bosses> bossList = new List<Bosses>();
public void loadBossData()
{
bossList.Add(new Bosses(sprites[0], score.timesEasy[0], new float[] { 3599, 45, 35 }, score.WA[0]));
//Exception thrown at line above
}
}
If you can help me out it would be greatly appreciated.
Comment
Your answer
Follow this Question
Related Questions
Get the base class from the derived class 1 Answer
How to store variables in a separate class 1 Answer
NullReferenceException: Object reference not set to an instance of an object 0 Answers
How to make objects without the new keyword 0 Answers
Several objects, same script, different values with no duplications 1 Answer