- Home /
Mecanim restricting animations problem
I have a gun model with a shoot, idle and reload animation. I've made it so that when you're reloading, you can't shoot. I want to make it so that if you reload while the shooting animation is ongoing, it'll stop shooting and start reloading. My problem is that it's doing that, but the reload animation doesn't finish. Right now, it starts the reloading animation, the animation plays for about 0.3 seconds, then it goes back to shooting. Here's my state machine: http://i.imgur.com/YCedlvn.png?1?2660 And here is my script:
currentBaseState = anim.GetCurrentAnimatorStateInfo(0);
if(canShoot && Ammunition > 0)
{
if(Input.GetButton("Fire1"))
{
anim.SetBool("Shot",true);
Shoot();
}
}
if(currentBaseState.nameHash == shootState)
{
anim.SetBool("Shot", false);
MuzzleFlashRenderer.enabled = false;
ShootLight.enabled = false;
}
if(Input.GetButtonDown("Reload") && Clips > 0)
{
anim.SetBool("Reload",true);
Reload();
}
if(currentBaseState.nameHash == reloadState)
{
anim.SetBool("Reload",false);
canShoot = false;
}
if(currentBaseState.nameHash == idleState)
{
canShoot = true;
}
I've had some luck by putting a canShoot = false; statement like so:
if(Input.GetButtonDown("Reload") && Clips > 0)
{
canShoot = false;
anim.SetBool("Reload",true);
Reload();
}
But it only works 1/3th of the time.
Comment