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
相关产品推荐
相关产品推荐

