Animation does not play

I am trying to make a fps game with custom animations but when i play the animation using a key the animation does not play but it dose not even show a error or something .I have even marked the animation as legacy. This is my code.

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

public class Fire_Pistol : MonoBehaviour
{
    public GameObject Pistol;
    public GameObject GameManager;
    public bool Firing = false;
    public Animation Anim;
    public GameObject MuzzleFlash;

    void Start()
    {
        Anim = GameManager.GetComponent<Animation>();
    }

    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            if (Firing == false)
            {
                StartCoroutine(FireThePistol());
            }
        }
    }

    IEnumerator FireThePistol()
    {
        Firing = true;
        Anim.Play("Fire_Pistol");
        MuzzleFlash.SetActive(true);
        yield return new WaitForSeconds(0.05f);
        MuzzleFlash.SetActive(false);
        Firing = false;
    }
}

@Sensei_Mala not sure if the muzzle flash particle effect is playing or not but id suggest using this script so that the muzzle flash effect doesn’t immediately stop after starting :

 IEnumerator FireThePistol()
 {
     Firing = true;
     Anim.Play("Fire_Pistol");
     MuzzleFlash.SetActive(true);
     yield return new WaitForSeconds(0.05f);
     Invoke("TurnOffMuzzleFlashEffect", timeToWaitBeforeTurningOffEffect);
     Firing = false;
 }

void TurnOffMuzzleFlashEffect()
{
       MuzzleFlash.SetActive(false);
}

The above script will hopefully solve the problem as i thought maybe the effect was being activated and then immediately deactivated, but if this is not the solution to your problem, or your problem at all, please let me know. Much love :slight_smile: