首页 > 解决方案 > unity - 键绑定打开和关闭动画

问题描述

我正在制作一个可以通过键绑定 (I) 访问的库存菜单。单击键绑定时,播放带入菜单的动画,如果再次单击键绑定,则应关闭菜单。不知道我要去哪里错了。

我已将动画控制器附加到 UI。

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

public class ShowInventory : MonoBehaviour {
    public Animator animator;

    // Update is called once per frame
    void Update() {
        if (Input.GetKeyDown(KeyCode.I)) {
            animator.SetBool("isOpen", true);
        }
    }
}

标签: c#animationunity3d

解决方案


除了代码之外,您还必须确保 Animator Controller 资产中的状态机也已正确设置。如果您还没有,请查看本教程:https ://unity3d.com/learn/tutorials/topics/animation/animator-controller


推荐阅读