public virtual void TakeHit(Bullet bullet) { if (!disabled) { SfxManager.instance.PlaySound(SoundType.SHIP_HURT); if (this.energy > 100) { this.energy = 100; } this.energy -= bullet.power * 20; float pauseTime = bullet.power / 15; DisplayUtil.FlashWhite(this, this.shipSprite, pauseTime); DisplayUtil.FlashWhite(this, this.characterSprite, pauseTime); GameManager.instance.ClearCombo(); if (bullet != null) { bullet.Die(); } StartCoroutine(GameManager.instance.PauseForSeconds(pauseTime, () => { Signals.Get <HitByBulletSignal>().Dispatch(new AttackData(this.type, bullet.owner, energy <= 0)); Camera.main.Shake(1f); })); } else { SfxManager.instance.PlaySound(SoundType.SHIP_HURT_AFTER_DEAD); invincible = true; Camera.main.GetComponentInChildren <HurtBG>().Show(); if (bullet != null) { bullet.Die(); } StartCoroutine(GameManager.instance.PauseForSeconds(bullet.power / 10, () => { Signals.Get <HitByBulletSignal>().Dispatch(new AttackData(this.type, bullet.owner, energy <= 0)); Camera.main.Shake(1.3f); })); GameManager.instance.AddScore(-1000, transform.position); } }
public virtual void TakeHit(Bullet bullet) { if (GameManager.instance.paused) { return; } var shieldActive = this.hasShield && this.shieldHealth > 0; if (!shieldActive) { DisplayUtil.FlashWhite(this, this.sprite, bullet.power / 40); if (this.playHitSound) { SfxManager.instance.PlaySound(SoundType.ENEMY_HURT); } } StartCoroutine(GameManager.instance.PauseForSeconds(shieldActive ? 0.005f : 0.01f * hitStopMultiplier, () => { Camera.main.Kick(bullet.velocity * (bullet.power / 4)); if (hasShield && shieldHealth >= 0) { if (bullet.color == shieldColor) { float tempShieldHealth = this.shieldHealth; this.shieldHealth -= bullet.power; bullet.power -= tempShieldHealth; if (this.shieldHealth <= 0) { this.outline.Clear(); this.outline.enabled = false; this.hasShield = false; Camera.main.Shake(0.6f); GameObject explosionCopy = Instantiate(explosion); SfxManager.instance.PlaySound(SoundType.SHIELD_DESTROYED, 1.2f); explosionCopy.transform.localScale -= Vector3.one * 0.25f; explosionCopy.transform.position = transform.position + (Vector3)offset; } else { DisplayUtil.FlashOutlineWhite(this, this.outline, bullet.power); } } else { SfxManager.instance.PlaySound(SoundType.SHIELD_DEFLECT); var offsetVector = (bullet.transform.position - transform.position).normalized * bullet.velocity.magnitude; bullet.velocity = offsetVector; } } else { float tempHealth = this.health; this.health -= bullet.power; bullet.power -= tempHealth; } Signals.Get <HitByBulletSignal>().Dispatch(new AttackData(this.type, bullet.owner, this != null && this.health <= 0)); if (bullet != null && bullet.power <= 0) { bullet.Die(); } if (this != null && this.health <= 0) { this.Die(true); } })); }