I am trying to create 2 arrays which will be string arrays for each team.
I create this class
public class MyTeamWeapons
{
public string[] weapons;
}
public class MyLoadout
{
public MyTeamWeapons[] teamWeapons;
public string[] playerModel;
}
I then try to create an instance and initialize the array with length of 5 filled will dummy data.
loadout = new MyLoadout();
loadout.teamWeapons = new MyTeamWeapons[2];
loadout.teamWeapons[0].weapons = new string[5] {"hellosd", "yous", "ds", "ad",
"dd"};
I get:
NullReferenceException: Object reference not set to an instance of an object
When trying to initialize new string array of 5. I do not understand why. All I want is 2 teams and each team have an array of strings to hold weapons names.
Any help would be great, thanks!