pistol shoot animation

So basically I’m trying to play the animation so when the animation is still playing I can restart it and play it again. Here’s my code

private Animator anim;
public AudioClip shoot;
public float damage = 10f;
AudioSource GunSound;
public float range = 100f;

public int maxAmmo = 10;
private int currentAmmo;
public float reloadTime = 1f;
private bool isReloading = false;
public int RestAmmo = 50;

public Camera fpsCam;

void Start () 
{
    currentAmmo = maxAmmo;
    anim = GetComponent<Animator>();
    GunSound = GetComponent<AudioSource>();
}

// Update is called once per frame
void Update () {

    if (isReloading)
        return;

    if (currentAmmo <= 0)
    {
        StartCoroutine(Reload());
        return;
    }

    if (Input.GetButtonDown("Fire1"))
    {
        GunSound.PlayOneShot(shoot, 0.7f);
        Shoot();
        anim.SetBool("fire", true);
    }
    else
    {
        anim.SetBool("fire", false);
    }

}

IEnumerator Reload ()
{
    Debug.Log("Reloading...");

    yield return new WaitForSeconds(reloadTime);

    currentAmmo = maxAmmo;
}

void Shoot ()
{

    RestAmmo--;
    currentAmmo--;

    RaycastHit hit;

	if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) 
	{
		Debug.Log(hit.transform.name);

		Target target = hit.transform.GetComponent<Target>();
		if (target != null) 
		{
			target.TakeDamage(damage);
		}
	}
}

}


It’s not a code issue, it’s a Unity Animator component toggle; you need to uncheck that box that has exit time in your transition for that animation.