Hey everyone, i’m trying to play a running animation on my mesh when Input.GetAxis(Horizontal) or Input.GetAxis(Vertical) is true. I watched a Youtube video but they only made the animation play when Input.GetAxis(Vertical) is true, now my animation only plays when the “a” key is pressed. How do i make it so that the animation plays when any of the “wasd” keys are pressed using the animator and scripting?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
//The speed of the player.
public float playerSpeed;
private float vert;
public Animator playerAnim;
void Start ()
{
playerAnim = GetComponent<Animator>();
}
void Update ()
{
//The movement of the player.
transform.Translate(Input.GetAxis("Horizontal") * playerSpeed * Time.deltaTime, 0f,
Input.GetAxis("Vertical") * playerSpeed * Time.deltaTime);
//Plays the "run" animation while the wasd keys are pressed.
vert = Input.GetAxis("Vertical");
playerAnim.SetFloat("run", vert);
}
}