public void ApplyDamage(Damage damage, Vector2 velocity) { if (recentDamagers.ContainsKey(damage.source)) { if (Time.time < recentDamagers[damage.source] + 1f) { return; } } recentDamagers[damage.source] = Time.time; float damageTaken = damage.baseDamage; switch (damage.type) { case DamageType.VelocityMitigated: damageTaken /= (1 + (controller.GetCar().GetComponent <Rigidbody2D>().velocity.magnitude * .5f)); break; case DamageType.VelocityAmplified: damageTaken *= velocity.magnitude / 25f; break; case DamageType.Fixed: default: break; } foreach (DamageFlag flag in damage.flags.Keys) { switch (flag) { case DamageFlag.Knockback: controller.GetCar().GetComponent <Rigidbody2D>().AddForce(velocity * damage.knockbackForce / velocity.magnitude); break; case DamageFlag.Wall: levelStats.AddStat(LevelRewards.ConditionType.WallContacts, 1f); break; case DamageFlag.Piercing: damageTaken *= (10f + currentArmor) / 10f; break; default: break; } } damageTaken *= 10f / (10f + currentArmor); if (damageTaken >= 1) { carSFX.PlayDamage(); } currentHealth -= damageTaken; levelStats.AddStat(LevelRewards.ConditionType.DamageTaken, damageTaken); }