I made an animation for my character to move in 4 directions but its only working with arrow or asdw keys not buttons… Does anyone know how to fix this? I don’t know what should I add to my script.
this is my player script
public class Player : MonoBehaviour
{
public Animator animator;
InputManager inputManager;
[SerializeField] float playerSpeed = 5f;
private void Awake()
{
inputManager = GetComponent<InputManager>();
}
void Update()
{
transform.Translate(inputManager.CurrentInput * Time.deltaTime * playerSpeed);
Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0.0f);
animator.SetFloat("Horizontal", movement.x);
animator.SetFloat("Vertical", movement.y);
animator.SetFloat("Speed", movement.magnitude);
}
}
And this is the script for my buttons
public class TouchButton : MonoBehaviour
{
bool pressedDown;
bool pressedLastFrame;
public InputManager.ButtonState CurrentState;
public void PressDown()
{
pressedDown = true;
}
public void Release()
{
pressedDown = false;
}
void Update()
{
if (pressedDown)
{
if (pressedLastFrame)
{
CurrentState = InputManager.ButtonState.Held;
}
else
{
CurrentState = InputManager.ButtonState.PressedDown;
}
}
else
{
if (pressedLastFrame)
{
CurrentState = InputManager.ButtonState.Released;
}
else
{
CurrentState = InputManager.ButtonState.None;
}
}
}
private void LateUpdate()
{
pressedLastFrame = pressedDown;
}
}