public void RemoveInvader(Invader invader) { invaders.Remove(invader); Destroy(invader); if (invaders.Count == 20) { speed = speed * 1.6f; fireRate = fireRate / 2; } if (invaders.Count == 10) { speed = speed * 1.6f; fireRate = fireRate / 2; } if (invaders.Count == 0) { gameController.CompleteLevel(); } }
void FireMissile() { if (player == null) { return; } Invader closestInvader = null; if (invaders.Count == 0) { return; } if (Random.value < accurateBombChance) { var closestDistance = 99999.0; invaders.ForEach(invader => { var thisDistance = Mathf.Abs(invader.gameObject.transform.position.x - player.transform.position.x); if (thisDistance < closestDistance) { closestInvader = invader; closestDistance = thisDistance; } }); } else { var index = Random.Range(0, Mathf.Max(0, invaders.Count - 1)); closestInvader = invaders[index]; } if (closestInvader != null) { closestInvader.GetComponent <WeaponController>().Fire(); } nextFire = Time.time + fireRate; }