using BaseGames.Player; using UnityEngine; namespace BaseGames.World { /// /// 危险区域。玩家进入时触发即死或持续伤害。 /// [RequireComponent(typeof(Collider2D))] public class HazardZone : MonoBehaviour { public enum RespawnType { AtLastSavePoint, AtRoomEntry } [SerializeField] private bool _isInstantKill = true; [SerializeField] private int _damage = 9999; [SerializeField] private RespawnType _respawnType = RespawnType.AtLastSavePoint; private void OnTriggerEnter2D(Collider2D other) { if (!other.CompareTag("Player")) return; var stats = other.GetComponentInParent(); if (stats == null) return; if (_isInstantKill) stats.TakeDamage(stats.MaxHP * 2); // 确保即死(超过最大血量) else stats.TakeDamage(_damage); } private void OnDrawGizmos() { Gizmos.color = new Color(1f, 0f, 0f, 0.3f); var col = GetComponent(); if (col != null) Gizmos.DrawCube(transform.position, col.bounds.size); Gizmos.color = new Color(1f, 0f, 0f, 0.8f); if (col != null) Gizmos.DrawWireCube(transform.position, col.bounds.size); } } }