private void Update() { if (_unitsInAttackRange.Count > 0 && _timeFromLastAttack >= _delayBetweenAttacks) { for (int i = 0; i < _unitsInAttackRange.Count; i++) { if (_unitsInAttackRange[i] == null) { _unitsInAttackRange.RemoveAt(i); i--; } else { if (_unitsInAttackRange[i].IsAlive == true) { _unitsInAttackRange[i].ApplyDamage(_enemy); _timeFromLastAttack = 0; Fireball fireball = Instantiate(_fireball, _shootPoint.position, Quaternion.identity); fireball.ApplyTarget(_unitsInAttackRange[i]); } return; } } } _timeFromLastAttack += Time.deltaTime; }