using UnityEngine;
/// <summary>
/// GAME 1303 Tier 4 — The bottomless pit. Anything with Health that falls in dies
/// instantly; anything else is destroyed (so enemies knocked off screen clean up too).
///
/// SETUP
/// - Big empty GameObject with a BoxCollider2D (Is Trigger) stretched below the level
/// (and beyond the sides if the level has open edges). Add this script.
/// - Kill Player Only: tick if you don't want stray props deleted.
///
/// Acid pools work the same way: trigger + this (or DamageOnContact with Instant Kill —
/// they're equivalent for the player; this one also tidies enemies).
/// </summary>
[RequireComponent(typeof(Collider2D))]
public class KillZone : MonoBehaviour
{
public bool killPlayerOnly = false;
public string sfxName = "fall";
void Reset() { GetComponent<Collider2D>().isTrigger = true; }
void OnTriggerEnter2D(Collider2D other)
{
bool isPlayer = other.CompareTag("Player");
if (killPlayerOnly && !isPlayer) return;
Health hp = other.GetComponentInParent<Health>();
if (hp != null)
{
hp.Kill();
if (isPlayer && !string.IsNullOrEmpty(sfxName)) AudioManager.Instance?.PlaySFX(sfxName);
}
else if (!isPlayer && other.attachedRigidbody != null)
{
Destroy(other.attachedRigidbody.gameObject);
}
}
}