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

Dropdown值变更触发Animator动画失败求助

(编辑于2024年1月6日)

各位大佬好!我最近在做通过TMP_Dropdown切换Animator整数参数的功能,已经按照@ITL的建议调整了代码,但还是没效果。从DebugLog里能看到Dropdown的选中值确实发生了变化,可Animator里对应的整数参数完全没跟着更新,动画自然也触发不了,实在卡在这里了。

下面是我当前的代码:

using UnityEngine.UI;
using TMPro;

public class AnimINTviaDropdown : MonoBehaviour
{
    public Animator animator; // Reference to the Animator component
    public int animIndex; // Index of the integer parameter in the Animator
    private TMP_Dropdown dropdown; // Reference to the TMP_Dropdown component

    private void Start()
    {
        dropdown = GetComponent<TMP_Dropdown>(); // Get the reference to the TMP_Dropdown component
        dropdown.onValueChanged.AddListener(OnDropdownValueChanged); // Subscribe to the value changed event
    }

    private void OnDropdownValueChanged(int selectedValue)
    {
       // Set the integer parameter value in the Animator
       animator.SetInteger(animIndex, selectedValue);
    }
}

有没有大佬能帮我排查下问题所在?

备注:内容来源于stack exchange,提问作者joe pie

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.17 08:58:18