How do I use 2 GetButtons at the same time?

Hello, i am working on an FPS and i have the walking animation for the gun set up to start and loop when the “w” key is pressed, and stop when I stop holding the “w” key. But now i have tried to add the sprinting animation for the gun, but when i press both the “w” and “sprint” keys it puts the gun it the right position but doesn’t go off frame 1 of the animation.

Here is the current script:

function Update () {
if (Input.GetButton(“w”)) {
animation.Play(“walking”);
}
if (Input.GetButton(“w”)) {
if (Input.GetButton(“Sprint”)) {
animation.Play(“running”);
}
}
}

i just want it to be like if i press both at once, it actually plays through the animation all the way through and loops until i stop holding the sprint button.

if(Input.GetButton("w")  Input.GetButton("Sprint"))
{
    //yada yada yada
}

O yeah sorry I forgot I posted it once already. But I tried what you said and it still produces the same effect: on pressing both at once the gun goes to frame 1 of the sprinting animation, but if I take my finger off the “w” key and keep holding “sprint”, it will play the animation and loop it like I want, but only if I’m standing still.

The problem is that every frame you’re Playing the walk animation, which stops the sprinting animation then playing the sprinting animation. Try something like:

if(Input.GetButton("w")  Input.GetButton("Sprint"))
{
    animation.Play("running");
}
else if(Input.GetButton("w"))
{
    animation.Play("walking");
}

Thank you very much that made it work. :slight_smile: