多轮审查和修复
This commit is contained in:
42
Assets/Scripts/World/HazardZone.cs
Normal file
42
Assets/Scripts/World/HazardZone.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
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;
|
||||
[SerializeField] private RespawnType _respawnType = RespawnType.AtLastSavePoint;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user