Animation replaying every frame...

This is my code to play animation on keypress (hold):

if(Input.GetKey(“w”) && Input.GetKey(“left shift”)){
GetComponent.().Play(“runfront”);
}

It is working but not correctly. It stays like this:
[72935-adsız.png|72935]

Plays one frame… I think it is from getkey codes but I tried getbutton, getbuttondown, getkeydown combinations. Only getkey plays animation. Others don’t.

That’s because every frame while you hold down w and shift buttons your animation starts to play. I don’t remember the exact variables for animation class but it should look something like this :

void Start() {
    anim = GetComponent<Animation>();
}

void Update() {
    if(Input.GetKeyDown(KeyCode.W) && Input.GetKeyDown(KeyCode)) {
        if(anim.isPlaying == false) {
            anim.Play();
        }
    }
}

That way your animation won’t try to play again while it’s playing.