/// <summary> /// Do the actual hit. /// </summary> /// <param name="other">Other.</param> virtual protected void DoHit(Collider2D other) { // If we are a one shot and have already fired we can't cause damage any more, if not continue if (!oneShot || !hasFired) { if (damageCharacters) { CharacterHurtBox hurtBox = other.gameObject.GetComponent <CharacterHurtBox>(); if (hurtBox != null) { damageInfo.Direction = transform.position - other.transform.position; damageInfo.DamageType = damageType; damageInfo.Amount = damageAmount; hurtBox.Damage(damageInfo); hasFired = true; } } if (damageEnemies) { EnemyHurtBox enemyHurtBox = other.gameObject.GetComponent <EnemyHurtBox>(); if (enemyHurtBox != null) { damageInfo.Direction = transform.position - other.transform.position; damageInfo.DamageType = damageType; damageInfo.Amount = damageAmount; enemyHurtBox.Damage(damageInfo); hasFired = true; } } } }
/// <summary> /// Do the actual hit. /// </summary> /// <param name="other">Other.</param> override protected void DoHit(Collider2D other) { CharacterHurtBox hurtBox = other.gameObject.GetComponent <CharacterHurtBox>(); // Don't trigger hazards from a dead enemy if (hurtBox != null && (enemy.State != EnemyState.DEAD) && (!hasFired)) { damageInfo.Direction = transform.position - other.transform.position; damageInfo.DamageType = damageType; damageInfo.Amount = damageAmount; damageInfo.DamageCauser = enemy; // Tell enemy we hit character - we need to do invulnerable check before we call Damage else the character may become invulnerable if (enemy != null && !hurtBox.IsInvulnerable) { enemy.HitCharacter(hurtBox.Character, damageInfo); } hurtBox.Damage(damageInfo); hasFired = true; } }
/// <summary> /// Unity late update hook. /// </summary> void LateUpdate() { // We process hits at the end of the frame so if physics calls multiple hitboxes we process character damage last // In other words if the cahracter both kills and gets killed by the enemy... the character "wins" if (deferredHit != null) { if ((enemy.State != EnemyState.DEAD) && (!oneShot || !hasFired)) { damageInfo.Direction = transform.position - deferredHit.Character.transform.position; damageInfo.DamageType = damageType; damageInfo.Amount = damageAmount; damageInfo.DamageCauser = enemy; // Tell enemy we hit character - we need to do invulnerable check before we call Damage else the character may become invulnerable if (enemy != null && !deferredHit.IsInvulnerable) { enemy.HitCharacter(deferredHit.Character, damageInfo); } deferredHit.Damage(damageInfo); hasFired = true; } } deferredHit = null; }