EvilChewwie
EvilChewwie

Reputation: 3

Unity - opening and closing animation with key binding

I'm making an inventory menu that will be accessed via a key binding (I). When the keybinding is clicked then play the animation which brings in the menu, if the keybind is clicked again then it should close the menu. Not sure where I'm going wrong here.

I've attached the animation controller to the 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);
        }
    }
}

Upvotes: 0

Views: 137

Answers (1)

bigfootaus
bigfootaus

Reputation: 1

As well as the code, you must also make sure your state machine in the Animator Controller asset is set up properly too. Check out this tutorial if you haven't already: https://unity3d.com/learn/tutorials/topics/animation/animator-controller

Upvotes: 0

Related Questions