I have a list of classes which I want to call upon, but the list count changes, so I have to make sure I don’t reference an index which doesn’t exist;
void Update()
{
{
Class class1 = listOfClasses[0];
if (Input.GetButtonDown("Fire1")) { class1.DoClass(); }
}
if (listOFClasses.Count <= 1)
{ return; }
else {
Class class2 = listOfClasses[1];
if (Input.GetButtonDown("Fire2")) { class2.DoClass(); }
}
etc etc
Is there some way I can use the List.Count to create the number of call functions I need, or some other better way, rather than checking the list count at every method call?