Why does this animation keep playing

I have tried lots of things, but can’t seem to find a solution, I have a character where the legs are a child object and they should only animate when I move the character (with WASD). Here’s the code:

using System.Collections;
using UnityEngine;

public class PlayerAnimate : MonoBehaviour {
Sprite walking, attacking, legsSpr;
int counter = 0, legCount = 0;
PlayerMovement pm;
float timer = 0.05f, legTimer = 0.05f;
public SpriteRenderer torso, legs;
SpriteContainer sc;
// Use this for initialization
void Start () {
pm = this.GetComponent();
sc = GameObject.FindGameObjectWithTag(“GameController”).GetComponent();
walking = sc.getPlayerUnarmedWalk();
legsSpr = sc.getPlayerLegs();
}

// Update is called once per frame
void Update () {
    animateLegs();
    animateTorso();
}

void animateTorso()
{
    if (pm.moving == true)
    {
        torso.sprite = walking[counter];
        timer -= Time.deltaTime;
        if (timer <= 0)
        {
            if (counter < walking.Length - 1)
            {
                counter++;
            }
            else
            {
                counter = 0;
            }
            timer = 0.1f;
        }
       
    }
}

void animateLegs()
{
    if (pm.moving == true)
    {
        legs.sprite = legsSpr [legCount];
        legTimer -= Time.deltaTime;

        if(legTimer <= 0)
        {
            if (legCount < legsSpr.Length - 1)
            {
                legCount++;
            }
            else
            {
                legCount = 0;
            }
            legTimer = 0.05f;
        }
    }
}

}

First I would Debug.Log(pm.moving) to make sure it is indeed false when you don’t want the animation to play.
If it is indeed false, check if there’s something else causing an animation. Are you sure you don’t have an Animator on the object, for example?