- Home /
Try to use keycode W&A
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerMovement : MonoBehaviour
{
[SerializeField]
private float _speed;
public Animator myAnim;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
// new vector3(1,0,0) *5*real time
float horizontalInput = Input.GetAxis("Horizontal");
float VerticallInput = Input.GetAxis("Vertical");
transform.Translate(new Vector3(horizontalInput,0, VerticallInput) *_speed * Time.deltaTime);
if
(Input.GetKey(KeyCode.W))
{
myAnim.SetBool("walk", true);
}
else if
(Input.GetKey(KeyCode.A))
{
myAnim.SetBool("walk_side", true);
}
else if
(Input.GetKey(KeyCode.S))
{
myAnim.SetBool("back_walk", true);
}
else if
(Input.GetKey(KeyCode.D))
{
myAnim.SetBool("walk_side", true);
}
else if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.A))
{
myAnim.SetBool("forward_left", true);
Debug.Log("forwardleft");
}
else
{
myAnim.SetBool("walk", false);
myAnim.SetBool("back_walk", false);
myAnim.SetBool("walk_side", false);
myAnim.SetBool("forward_left", false);
}
}
}
Comment