Files
zeling_v2/Assets/Scripts/World/HazardZone.cs
2026-05-12 21:50:49 +08:00

45 lines
1.4 KiB
C#

using BaseGames.Player;
using UnityEngine;
namespace BaseGames.World
{
/// <summary>
/// 危险区域。玩家进入时触发即死或持续伤害。
/// </summary>
[RequireComponent(typeof(Collider2D))]
public class HazardZone : MonoBehaviour
{
public enum RespawnType { AtLastSavePoint, AtRoomEntry }
[SerializeField] private bool _isInstantKill = true;
[SerializeField] private int _damage = 9999;
#pragma warning disable CS0414
[SerializeField] private RespawnType _respawnType = RespawnType.AtLastSavePoint;
#pragma warning restore CS0414
private void OnTriggerEnter2D(Collider2D other)
{
if (!other.CompareTag("Player")) return;
var stats = other.GetComponentInParent<PlayerStats>();
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<Collider2D>();
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);
}
}
}