You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity中Trigger Zone触发失效求助:OnTrigger函数未执行

Unity触发器函数无法执行问题
using UnityEngine;

public class TriggerZone : MonoBehaviour
{
    // 当其他碰撞体进入触发区域时调用此方法
    private void OnTriggerEnter(Collider other)
    {
        Debug.Log("WorkingIn");
        // 检查碰撞对象是否是玩家/主摄像机
        if (other.CompareTag("Player") || other.CompareTag("MainCamera"))
        {
            Debug.Log("Player entered the trigger zone.");
            // 在这里添加玩家进入触发区域时需要执行的操作或逻辑
        }
    }

    // 当碰撞体离开触发区域时调用此方法
    private void OnTriggerExit(Collider other)
    {
        Debug.Log("WorkingExit");
        // 检查碰撞对象是否是玩家/主摄像机
        if (other.CompareTag("Player") || other.CompareTag("MainCamera"))
        {
            Debug.Log("Player exited the trigger zone.");
            // 在这里添加玩家离开触发区域时需要执行的操作或逻辑
        }
    }
}

无论如何,上述两个函数始终无法执行。原本单个GameObject即可满足碰撞检测需求,但由于功能失效,我添加了多个对象。相关截图如下:

触发器对象设置1
触发器对象设置2
触发器对象设置3

内容的提问来源于stack exchange,提问作者Wakeel Furqan Ahmed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 23:23:14