walk and run animation

hello,

i am working on a character animation for idle, walk and running.

i have the animator setup and it works fine. but now the scripting part.

this is what i have:

usingUnityEngine;
usingSystem.Collections;
publicclass animation :MonoBehaviour
{
Animator m_animator;
voidStart()
{
m_animator =GetComponent<Animator>();
}
voidUpdate()
{
bool isWalkingPressed =Input.GetKey("w");
m_animator.SetBool("isWalking", isWalkingPressed);
bool isRunningPressed =Input.GetKey("left shift"&"w");
m_animator.SetBool("isRunning", isWalkingPressed);
}
}

the walking bool works fine. when i enter play mode and press W it starts to walk. the running bool isn’t working. it’s because of the &. how do i do this the right way?

@stefanwillems

Hi there,

bit hard to say what is going on as you don’t show an image of your animator, but there is at least a problem in your code:

bool isRunningPressed =Input.GetKey("left shift"&"w");

GetKey doesn’t work like that AFAIK. You’ll have to do two comparisons. Also, using one “&” for comparison doesn’t work in C#. Instead of what you now have, try:

bool isRunningPressed = Input.GetKey("left shift") && Input.GetKey("w");

thanks for your reply!

im kinda new to coding. was already suprised that it worked this far :slight_smile:

i will try this.

EDIT: thanks alot works fine now! could you help me with something else. has to do with the animation aswell. here is a link if u want to: https://forum.unity3d.com/threads/animation.441552/