public override void ActivatePowerUp(Transform parent) { base.PowerUpActive = true; int asteroidChildCount = _asteroidHolder.childCount; if (asteroidChildCount > 0) { int randomIndex = Random.Range(0, 1000) % asteroidChildCount; HealthSetter asteroidHealthSetter = _asteroidHolder.GetChild(randomIndex).GetComponent <HealthSetter>(); asteroidHealthSetter.ReduceHealth(int.MaxValue); return; } int spaceshipChildCount = _spaceshipHolder.childCount; if (spaceshipChildCount > 0) { int randomIndex = Random.Range(0, 1000) % spaceshipChildCount; HealthSetter spaceshipHealthSetter = _spaceshipHolder.GetChild(randomIndex).GetComponent <HealthSetter>(); spaceshipHealthSetter.ReduceHealth(int.MaxValue); } base.DeactivatePowerUp(); }
private void DecreaseHealthOnContact(HealthSetter healthSetter, GameObject other) { if (_targetPlayer) { if (!other.CompareTag(TagManager.Player)) { return; } healthSetter.ReduceHealth(_affector.Amount); } else { healthSetter.ReduceHealth(_affector.Amount); } }
private void OnCollisionEnter2D(Collision2D other) { if (_objectRb.velocity.sqrMagnitude < _minAffectMagnitude) { return; } if (_affectOnlyPlayer) { if (other.gameObject.CompareTag(TagManager.Player)) { HealthSetter playerHealthSetter = other.gameObject.GetComponent <HealthSetter>(); playerHealthSetter.ReduceHealth(_damageAmount); } } else { HealthSetter healthSetter = other.gameObject.GetComponent <HealthSetter>(); if (healthSetter != null) { healthSetter.ReduceHealth(_damageAmount); } } }