Hello, can someone help me with animating my UI?

Hello! Im having some trouble with getting animations to work with my UI.


Its just a simple UI. When u click the hamburger button(menu button) it slides left and shows the hidden content which are located outside of the screen view.

heres my codes:

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

public class MenuController : MonoBehaviour
{
    public Button menuButton;




    public void Start()
    {

        Button btn = menuButton.GetComponent<Button>();


        
        btn.onClick.AddListener(openMenuOn);




    }
    public void openMenuOn () 
    {
        Debug.Log("click");

        if (menuButton != null)
        {
            Animator animator = GetComponent<Animator>();
            {
                bool isOpen = animator.GetBool("MenuOpen");

                
                if(isOpen == true)
                {
                    animator.SetBool("MenuOpen", false);

                    Debug.Log("menu is closed");
                }
     
                else if(isOpen == false)
                {
                    animator.SetBool("MenuOpen", true);
                    Debug.Log("menu is opened");
                }
                


            }
        }
    }
}

so the debug log shows when I click, which i means only part thats not working is the animation part, which changes the animation according to the bool value i set (MenuOpen).
Doesnt anybody see whats wrong with this?

For "MenuClose "try to not transition back into “new state” just back into “MenuOpen” with bool false.


And for first state better direction it to “MenuClose” if the ui not showing, it depends it showing first or not.


And for Animator animator = GetComponent<Animator>(); better do in start, don’t initiate many time, just 1 time if it can.


Hope it help.