- Home /
Character will not go from Ide to Walk
When I press the up and own arrows, the scene moves up and down but the character will not transition from Idle State to Walk. Same with pressing the letter keys. The script is attached to the character called Soldier, the Soldier is in the Player field, and the Animation Controller is also named soldier as can be seen in the attached picture. The script code is as follows:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class TankControls : MonoBehaviour {
public GameObject thePlayer;
public bool isMoving;
public float horizontalMove;
public float verticalMove;
void Update ()
{
if (Input.GetButton("Horizontal") || Input.GetButton("Vertical"))
{
isMoving = true;
thePlayer.GetComponent<Animator>().Play("Walk");
horizontalMove = Input.GetAxis("Horizontal") * Time.deltaTime * 150;
verticalMove = Input.GetAxis("Vertical") * Time.deltaTime * 3.9f;
thePlayer.transform.Rotate(0, horizontalMove, 0);
thePlayer.transform.Translate(0, 0, verticalMove);
}
else
{
isMoving = false;
thePlayer.GetComponent<Animator>().Play("Idle");
}
}
}
Answer by HypoSlyper · Dec 26, 2021 at 07:06 AM
'Input.GetButton' should be replaced by 'Input.GetAxis'
Your answer
Follow this Question
Related Questions
Why are my animations not working correctly? Thanks! 0 Answers
Quaternion issue: how can I fix this? 0 Answers
How can I have a CharacterController's height make it to where the feet are correctly on the ground? 0 Answers
2D Character Animation - even starting if I'm not pressing A or D 2 Answers
My Animation Is Stuck On A Frame 0 Answers