How to trigger an animation from a ui button

I’m a complete noob. I decided to make a game but I want to press a gear icon to launch a settings menu. I want a dark think to slide from the left. I made the object I want and the animation it should play but I can’t trigger it by clicking the button no matter which tutorial I tried.
I attached a photo with my scene. The gear in the top right is the button I want to click and the object outside the scene is the one I want to slide from the left.
Any ideas?

Here is a solution of how to do this without any “Animation”:

To use my solution here is what you need to do:

  1. Make a settings panel, wit no animations. (Just a simple panel).
  2. Anchor the panel to the middle of your Canvas: 178823-112.png
  3. Move the panel to the left, where it is offscreen (Start Position).
  4. Make a button to “Summon” your “Settings Panel”.
  5. Make a button on your “Settings Panel”, to close it. (Close Button).
  6. Now create a new script on your “Settings Panel” and call it: panelMovementScript (Name it exactly this, to make it easier).
  7. Open your new script, select everything, and delete it.
  8. Copy my entire script below, paste it into yours, and save it.
  9. Now on your “Summon Panel Button” (gear button): At the bottom where it says “OnClick()”, click the “+” sign.
  10. Drag your “Settings Panel” into the “None (Object)” field.
  11. Click the “No Function” dropdown: panelMovementscript > initiatePanelTransition()
  12. Do the exact same on your “Close Settings Button”, but at the “No Function” dropdown, choose: panelMovementscript > movePanelBack()

Script mentioned at step 8:

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

public class panelMovementScript : MonoBehaviour
    public float speed;
    bool fireOnce;
    bool movePanel;

    Vector3 startPosition;
    private void Start()
        speed = 500f; // can be changed in unity editor
        startPosition = gameObject.transform.localPosition;

    public void initiatePanelTransition()
        movePanel = true;

    public void movePanelBack()
        gameObject.transform.localPosition = startPosition;
        fireOnce = false;

    void Update()
        if (movePanel)
            if (!fireOnce)
                if (transform.localPosition.x < 0)
                    transform.Translate(Vector3.right * Time.deltaTime * speed);
                    transform.localPosition = new Vector3(0, 0, 0);
                    fireOnce = true;
                    movePanel = false;
                    Debug.Log("Moved Into Position");


Create animation in unity.
Create C# script for controlling this function.
Add a following content into your class:
public class YourClassName : MonoBehaviour
// Add an animation component to your object in unity inspector
// Assign that animation component to this
public Animation animation;

    public void YourCustomFunctionName() 

Assign your animation to animation component which you must have in your controller
Call this function your button component onClick field