Trigger Activated Multiple Times From One Click

In Mecanim, I have a couple trigger values that activate animations. I have a C# script reading the input, but when the mouse is clicked, for example, it may read in multiple clicks in one frame. This ends up activating the trigger twice in a row, making the animation glitchy. How do I prevent this from happening?

Here’s part of my code. As you can see, I even check to see if the animation is playing to prevent reading in multiple clicks, but I guess this doesn’t account for the transition time or something.

if(Input.GetKey(swing)) {
    if(!anim.GetCurrentAnimatorStateInfo(0).IsName("Swing")) {
            anim.SetTrigger("Swinging");
    }
}

Use GetKeyDown. It will only trigger once

I fixed the problem, /u/FluxCapacimator on Reddit came up with the answer. Link to the reddit post: Reddit - Dive into anything

Here’s the code that fixed the problem:

// in your class
float nextswing = 0;
...
// in your update
if( Input.GetKey(x) && Time.time > nextswing  )
{
    swing();
    nextswing = time.time + 0.5f;
}