Hi!
I am new to Unity. I am trying to do easy game, but I am struggling with some script or animation thing. I’ve got 4 + 1 moves: WalkFwd, WalkBwd, WalkL and WalkR…But the only one thing that really works on key press is the last one in script - WalkR. Every other animation is stuck in some weird lag. I press it, it is moving really slowly but it looks like that animation starts and stops and it is in one infinite loop (looks like vibrating).
Here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharactersAnimationScript : MonoBehaviour {
private Animator anim;
// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update()
{
if(Input.GetKey(KeyCode.S)) {
anim.CrossFade ("KB_WalkBwd", 0);
anim.SetBool ("IsWalkingBwd", true);
anim.SetBool ("IsIdle", false);
}
else {
anim.SetBool ("IsWalkingBwd", false);
anim.SetBool ("IsIdle", true);
}
if(Input.GetKey(KeyCode.W)) {
anim.CrossFade ("KB_WalkFwd2", 0);
anim.SetBool ("IsWalkingFwd", true);
anim.SetBool ("IsIdle", false);
}
else {
anim.SetBool ("IsWalkingFwd", false);
anim.SetBool ("IsIdle", true);
}
if(Input.GetKey(KeyCode.A)) {
anim.CrossFade ("KB_WalkLeft135", 0);
}
if(Input.GetKey(KeyCode.A)) {
anim.SetBool ("IsWalkingL", true);
anim.SetBool ("IsIdle", false);
}
else {
anim.SetBool ("IsWalkingL", false);
anim.SetBool ("IsIdle", true);
}
if(Input.GetKey(KeyCode.D)) {
anim.CrossFade ("KB_WalkRight135", 0);
anim.SetBool ("IsWalkingR", true);
anim.SetBool ("IsIdle", false);
}
else {
anim.SetBool ("IsWalkingR", false);
anim.SetBool ("IsIdle", true);
}
}
}