Hi, I’m new to Unity and game engines in general. I’m trying to make a 3rd person 1v1 sort of game, but I’m stuck with animations. I have set up basic movement animations but when I would press a key such as ‘W’ to move the character forward, the walk animation would play forever. Furthermore, if I press ‘Space’ to Jump and then right after press another animation key, the Jump animation would instantly cancel out and play the other animation.
What I’m wondering is how do I stop the ‘Jump’ animation from canceling when I press another key and how do I make movement animation play only when holding down the key and stopping them when I let go. (FYI, the anim.Stop command doesn’t work for some reason).
I would greatly appreciate it if someone could help me out!
Thanks a lot!
My animation code is below:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KnightAnim : MonoBehaviour {
private Animator anim;
void Start () {
anim = GetComponent<Animator> ();
}
void Update () {
if (Input.GetButtonDown ("Jump"))
anim.Play ("Jump");
if (Input.GetKeyDown(KeyCode.UpArrow))
anim.Play ("Walk");
if (Input.GetKeyDown (KeyCode.W))
anim.Play ("Walk");
if (Input.GetKeyDown(KeyCode.Q))
anim.Play ("Run");
if (Input.GetKeyDown(KeyCode.LeftArrow))
anim.Play ("StrafeLeft");
if (Input.GetKeyDown(KeyCode.A))
anim.Play ("StrafeLeft");
if (Input.GetKeyDown(KeyCode.RightArrow))
anim.Play ("StrafeRight");
if (Input.GetKeyDown(KeyCode.D))
anim.Play ("StrafeRight");
if (Input.GetKeyDown(KeyCode.DownArrow))
anim.Play ("WalkBack");
if (Input.GetKeyDown(KeyCode.S))
anim.Play ("WalkBack");
if (Input.GetKeyDown (KeyCode.E))
anim.Play ("RunJump");
}
}