private void PlayerHit() { CameraShake.Instance.TriggerShake(); particleController.InstantiateParticleOfType(ParticleType.PLAYER_HIT, transform.position); soundManager.PlaySound("PlayerHit"); StartCoroutine(HandleHitPostFX()); HandleHealth(); void HandleHealth() { if (!hitRecently) { hitRecently = true; Invoke("ResetHitGracePeriod", hitGraceSeconds); anim.SetTrigger("Hit"); } else // If hit recently, give damage grace so they don't get comboed { return; } health--; HealthUI.Instance.UpdateUIHeart(health); if (health <= 0) { EventManager.OnGameOver?.Invoke(); } } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Respawn")) { if (doNothing) { return; } particleController.InstantiateParticleOfType(ParticleType.PLAYER_HIT, transform.position); SoundManager.Instance.PlaySound("PlayerHit"); if (respawnAfterHit) { transform.position = respawnPoint.position; } if (switchSceneAfterHit) { SceneManager.LoadScene(sceneToSwitch); } } }