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

Unity中按E触发Animator无响应求助(手动触发正常)

Unity相机碰撞交互与马桶盖动画触发异常问题

我在Unity中实现了相机碰撞体与物体的交互功能,已配置Animator并创建名为press的Trigger。手动在Animator面板触发press时一切正常,但按下E键时,要么动画出错、触发了其他对象的动画,且能看到并未关联到我设置的Animator(过渡效果未高亮)。

为了仅驱动马桶盖动画,我将其他子物体设为静态,避免整体马桶错位。目前仅手动触发press能实现预期效果,按E键完全无效。

相关截图

对应脚本代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class pooplol : MonoBehaviour
{
    public Animator Toilet;
    public AudioSource kmms;
    public GameObject inttext;

    private bool isInteractable = false;

    void Start()
    {
        // Try to fetch the Animator component
        Toilet = GetComponent<Animator>();
        if (Toilet == null)
        {
            Debug.LogError("Animator component not found on the GameObject to which this script is attached.");
        }
    }

    void Update()
    {
        if (isInteractable && Input.GetKeyDown(KeyCode.E))
        {
            Debug.Log("E key pressed and interactable is true.");
            Toilet.ResetTrigger("press");
            Toilet.SetTrigger("press");
        }
    }

    void OnTriggerStay(Collider other)
    {
        if (other.CompareTag("MainCamera"))
        {
            inttext.SetActive(true);
            isInteractable = true;
            Debug.Log("MainCamera is within trigger area.");
        }
    }

    void OnTriggerExit(Collider other)
    {
        if (other.CompareTag("MainCamera"))
        {
            inttext.SetActive(false);
            isInteractable = false;
            Debug.Log("MainCamera has exited the trigger area.");
        }
    }
}

内容的提问来源于stack exchange,提问作者Karim Elhusseiny

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 11:06:21