I started unity yesterday and I tried to bind moving left, right, up and down with animation controller, but my character doesn’t watch right direction. It would be pleasure what is wrong with me.
I set all transition’s from Idle and animation state conditions true and false.
Also, parameters are all bool
ean values
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movement : MonoBehaviour
{
[SerializeField]
private float moveSpeed;
private Animator anim;
void Start()
{
//the issue:
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
float horizontalInput = Input.GetAxisRaw("Horizontal");
float verticalInput = Input.GetAxisRaw("Vertical");
Vector3 moveTo = new Vector3(horizontalInput, verticalInput, 0);
transform.position += moveTo * moveSpeed * Time.deltaTime;
if (Input.GetKey(KeyCode.LeftArrow)){
anim.SetBool("moveLeft", true);
}
else if(Input.GetKey(KeyCode.RightArrow)){
anim.SetBool("moveRight", true);
}
else if(Input.GetKey(KeyCode.UpArrow)){
anim.SetBool("moveUp", true);
}
else if(Input.GetKey(KeyCode.DownArrow)){
anim.SetBool("moveDown", true);
}
}
}