Hi ! Currently trying to use an array with a public class, like so:
Adventurers[] AdventurersArray = new Adventurers[128];
public Text txt_Name, txt_HP, txt_Ability;
public class Adventurers
{
public int advID;
public string name;
public int hp;
public string ability;
}
public void Update()
{
}
public void btt_GenerateAdventurer() //test button that generate an adventurer
{
AdventurersArray[0].name = "kevin";
AdventurersArray[0].hp = Random.Range(0, 10);
AdventurersArray[0].ability = "fireball";
txt_Name.text = "Name: " + AdventurersArray[0].name;
txt_HP.text = "HP: " + AdventurersArray[0].hp;
txt_Ability.text = "Ability: " + AdventurersArray[0].ability;
}
That’s what I came with after some looking up here and there. But, it of course don’t work and the console says “NullReferenceException: Object reference not set to an instance of an object” on line 32. What should I do to make it work ? Thanks in advance.