using UnityEngine; public class Trap : MonoBehaviour { public float bounceForce = 10f; public float damage = 1f; // Start is called once before the first execution of Update after the MonoBehaviour is created void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.CompareTag("Player")) { HandlePlayerBounce(collision.gameObject); SoundEffectManager.Play("Bounce"); } Enemy enemy = collision.GetComponent(); if (enemy) { // Instantly kill the enemy by dealing at least maxHealth damage enemy.TakeDamage(enemy.maxHealth, false); } } private void HandlePlayerBounce(GameObject player) { Rigidbody2D rb = player.GetComponent(); if (rb) { // Reset player velocity rb.linearVelocity = new Vector2(rb.linearVelocity.x, 0f); // Apply bounce force rb.AddForce(Vector2.up * bounceForce, ForceMode2D.Impulse); // Reset jumps after bounce var movement = player.GetComponent(); if (movement != null) { movement.ResetJumps(); } } } }