Basically the title. Am I doing something wrong? I initialize the list at Start so that I can insert some elements at a specific place, but when the time comes to do so, the list gives me an out of range error. I’m making a card game and the enemy (which knows it’s position in the lineup of enemies) needs to know if it’s being attacked or not by checking the QueuedAttacks list at its position. I’m guessing this is a drawback of the List interface? It sees that position 0 is null, so it thinks it’s empty or something?
Anybody wise to what’s happening?
void Start () {
QueuedAttacks = new List<GameObject>(number_of_monsters);
}
...
IEnumerator MoveToAttack (Transform child, Transform startingPlace, Vector3 endingPlace, float time) {
float t = 0f;
while (t < 1.0f){
t += Time.deltaTime / time;
child.transform.position = Vector3.Lerp(startingPlace.position, endingPlace, t);
yield return new WaitForEndOfFrame();
}
child.GetComponent<WeaponController>().PrepareForBattle(PartyOfPlayers[0], selectedMonster);
QueuedAttacks.Insert(current_monster, child.gameObject);
// ^ this is where the error is //
StartCoroutine(child.GetComponent<WeaponController>().Attack(selectedMonster));
}