Just finished the Constant Swinging lesson and its working fine UNLESS I quickly let off and click the mouse again. In which case, the swing speeds up … if I click several times, my sword swings very very quickly. This may get addressed later but I thought I’d put this here in case it doesnt.
I handled this with a bool isAttacking that starts and ends the attacking coroutine. Then I don’t start the attacking coroutine if isAttacking
void StartAttacking()
{
attackButtonDown = true;
if(!isAttacking)
{
StopAllCoroutines();
StartCoroutine(AttackSequence());
}
}
void StopAttacking()
{
attackButtonDown = false;
}
IEnumerator AttackSequence()
{
isAttacking = true;
while (attackButtonDown)
{
Attack();
yield return new WaitForSeconds(TimeBetweenAttacks);
}
isAttacking = false;
}
1 Like