# putting a delay between animation looping

I've got a player swinging a sword, this animation is controlled by a state machine. However, I don't want the player to be continuously swinging the sword when he's attacking -- I want him to swing once, wait a bit, then swing again. The animation in the animator controller has a speed variable I can control, but this merely makes each swing slower or faster -- I want the swing speed to be the same, just have a pause before the animation loops again. How should I do it?

When you accept the character input, you can verify if a certain delay has passed, before you allow the input to be submitted again.

float Delay = 3f;

void Update()
{
Delay -= Time.deltaTime;

if (Delay <= 0 && Input.GetKey(Keys.Attack))
{
Attack();
Delay = 3f;
}
}


You should use programming if unity does not have the option. For unreal engine 4, there is an animation delay but programming is the best choice.

It should be like loop animation1 and wait for the seconds you want.

Another option is to add idle frames to the attack animation strip to fit the timing that you want, but it's less efficient than passing a delay as Jon suggests.

Alternatively if you are using the AnimationState object, you can impose delays between transitions between the looping of the attack state.