Sword combos
The player’s sword attacks use animation events to control hit timing. A hit check finds nearby colliders and applies damage to objects that implement IDamageable.
Gameplay video
Sword hit check
void PerformAttack()
{
Collider[] hitColliders = Physics.OverlapSphere(attackPoint.position, attackRadius);
foreach (Collider hit in hitColliders)
{
IDamageable damageable = hit.GetComponent<IDamageable>();
if (damageable != null)
{
damageable.TakeDamage(weaponDamage);
}
}
}
Finds colliders inside the attack radius and calls TakeDamage() on those with IDamageable.
Starting an attack
public void StartAttack()
{
if (canAttack && !isAttacking)
{
animator.SetTrigger("Attack");
isAttacking = true;
}
}
Starts the attack animation when canAttack is true and isAttacking is false.