so i finally got my gun to play an animation on every shot with
function Update () {
if (Input.GetButton("Fire1")) {
animation.Play("boltaction");
}
}
But it doesn't completely satisfy me because it still happens if i'm reloading or something.
How do i make it play just when the gun shots or something?
if (the exact situation you will permit the animation to play occurs)
{
playTheAnimation;
}
what you have now is:
if(the fire one button was pressed)
{
playTheAnimation;
}
In fact the computer is simply doing exactly what you told it to do.
The quickest way to fix this is
Make a boolean called "mayShootNow"
In the update check if the situation permits the animation to play, here you have to pick a parameter and use it like a door, when do you want it opened ? When the key was released? When the character is not walking? Whenever another animation is done playing? You need to figure out what the event is that permits the animation play event. Once you have that gateway setup done you need to update it.
if (mayShootNow && fire button)
{
fireEvent (playAnimation, playSound, fireBullet)?
}