Files
2025TapTapGameJam/Assets/Script/Gameplay/Combat/CombatTrigger.cs
2025-10-15 21:31:13 +08:00

50 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using UnityEngine;
using Gameplay;
using Share;
using Gameplay.Enemy;
using Gameplay.Player;
namespace Gameplay.Combat
{
[RequireComponent(typeof(Collider))]
public class CombatTrigger : MonoBehaviour
{
//[Tooltip("战斗管理器引用(场景中单例/对象)")]
private CombatFlowManager combatManager;
[Tooltip("触发时指定的玩家 Combatant可为空manager 使用已配置的)")]
public PlayerController player;
[Tooltip("触发时指定的敌人 Combatant可为空manager 使用已配置的)")]
public EnemyController enemy;
[Tooltip("被触发后是否自动禁用触发器,避免重复触发")]
public bool disableAfterTrigger = true;
private void Start()
{
combatManager = CombatFlowManager.Instance;
}
private void Reset()
{
// Collider 需要 isTrigger
var col = GetComponent<Collider>();
col.isTrigger = true;
}
private void OnTriggerEnter(Collider other)
{
// 简单检测:玩家层或带有 "Player" 标签的物体
if (combatManager == null) return;
if (other.CompareTag("Player") || other.gameObject.layer == LayerMask.NameToLayer("Player"))
{
combatManager.StartCombat(player, enemy);
if (disableAfterTrigger) gameObject.SetActive(false);
}
}
}
}