Question by 
               ramliz · May 01, 2016 at 04:13 PM · 
                animationanimatormouseclick  
              
 
              Fast Clicking problem
The Game is an fps shooter, when pressing mouse button at steady normal rate it plays out fine but if i bash the mouse button animations get out of sync and audio too. here is the code note that to play Shoot(); I check for idle animation yet when i click very fast the code seems to run even when FIre animation is running.
using UnityEngine; using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class MagScript : MonoBehaviour { bool fire; Animator animator; int ammo; public AudioClip shot;
 // Use this for initialization
 void Start () 
 {
     animator = GetComponent<Animator>();
     ammo = 6;
 }
 
 // Update is called once per frame
 void Update () 
 {
    
     if (Input.GetButtonDown("Fire1"))
     {
         if (this.animator.GetCurrentAnimatorStateInfo(0).IsName("Idle") && ammo != 0)
         {
             Shoot();
         }
        
     }
     else
     {
         animator.SetBool("Shoot", false);
     }
     if (ammo == 0 && animator.GetBool("Shoot") == false)
     {
         animator.SetBool("Reload", true);
         ammo = 6;
     }
     if (this.animator.GetCurrentAnimatorStateInfo(0).IsName("Reload"))
     {
         animator.SetBool("Reload", false);           
     }
 }
 void Shoot()
 {
     animator.SetBool("Shoot", true);
     GetComponent<AudioSource>().clip = shot;
     GetComponent<AudioSource>().Play();
     ammo -= 1;
 }
 
               }
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Is OnMouseUpAsButton() can be called only once ? 2 Answers
Can't play an animation from the Animator 1 Answer
stickman animation 1 Answer
Broken animations in Unity 5.3.5f 1 Answer