- Home /
Question by
Rtun7939 · Jul 06, 2020 at 10:34 AM ·
animationsboolcrossfadeframeskipping
Unity plays the animation then jumps to another, then back again.
I have 5 animations for a pistol, including an Idle animation as the Entry Animation. When I press "w" it plays the running animation. When I press"D" it plays the reaching right animation. "When I left click, it plays the firing animation. When I press "a", it's supposed to play the reach left animation, but it plays one frame of the idle animation before going back to the reach left animation. Can someone help? I used SetBool and CrossFades.
P.S: I'm new to Unity, so I don't know very much. MY CODE: public class PistolAnimations : 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()
{
//Pistol Firing Animation Script
if(Input.GetKeyDown(KeyCode.Mouse0))
{
anim.CrossFade ("Pistol Firing", 0.0000001f);
}
//Pistol Running Animation Scipt (This took a REALLY long time to fix after I added the third anim.)
if (Input.GetKey(KeyCode.W))
{
anim.Play ("Pistol Running");
anim.SetBool("isRunning", true);
anim.SetBool("isIdle", false);
}
else
{
anim.SetBool("isRunning", false);
anim.SetBool("isIdle", true);
}
//Pistol going to the left animation Script (This one took a long time too.)
if (Input.GetKey(KeyCode.A))
{
anim.CrossFade("Pistol Left", 0.0001f);
anim.SetBool("isLeft", true);
anim.SetBool("isIdle", false);
}
else
{
anim.SetBool("isLeft", false);
anim.SetBool("isIdle", true);
}
//And dis is the Pistol going to the right anim script .YA.
if (Input.GetKey(KeyCode.D))
{
anim.CrossFade("Pistol Right", 0.0000000000000000000000000000000000000000000000000001f);
anim.SetBool("isRight", true);
anim.SetBool("isIdle", false);
}
else
{
anim.SetBool("isRight", false);
anim.SetBool("isIdle", true);
}
}
}
Comment