/// <summary> /// Emit damage based on a raycast hit. /// </summary> /// <param name="hit">The raycast hit information.</param> public void RaycastHitDamage(RaycastHit hit) { DamageReceiver damageReceiver = hit.collider.GetComponent <DamageReceiver>(); if (damageReceiver != null) { if (damageReceiver.RootTransform == rootTransform) { return; } for (int i = 0; i < healthTypeDamageValues.Count; ++i) { if (healthTypeDamageValues[i].HealthType == damageReceiver.HealthType) { float damage = healthTypeDamageValues[i].DamageValue; if (damagePerSecond) { damage *= Time.deltaTime; } damageReceiver.Damage(damage, hit.point, damageSourceType, rootTransform); } } } }
/// <summary> /// Emit damage based on a raycast hit. /// </summary> /// <param name="hit">The raycast hit information.</param> public virtual void RaycastHitDamage(RaycastHit hit) { DamageReceiver damageReceiver = hit.collider.GetComponent <DamageReceiver>(); if (damageReceiver != null) { // Don't apply damage or healing to self if (damageReceiver.RootTransform == rootTransform) { return; } // Do damage float damageValue = defaultDamageValue * (timeBased ? Time.deltaTime : 1); for (int i = 0; i < damageOverrideValues.Count; ++i) { if (damageOverrideValues[i].HealthType == damageReceiver.HealthType) { float damageAmount = damageFalloffCurve.Evaluate(Vector3.Distance(transform.position, hit.point) / maxEffectDistance); damageValue = damageOverrideValues[i].Value * damageAmount; if (timeBased) { damageValue *= Time.deltaTime; } } } if (damageValue != 0) { damageReceiver.Damage(damageValue, hit.point, healthModifierType, rootTransform); } // Calculate healing value float healingValue = defaultHealingValue * (timeBased ? Time.deltaTime : 1); for (int i = 0; i < healingOverrideValues.Count; ++i) { if (healingOverrideValues[i].HealthType == damageReceiver.HealthType) { float healingAmount = damageFalloffCurve.Evaluate(Vector3.Distance(transform.position, hit.point) / maxEffectDistance); float healing = healingOverrideValues[i].Value * healingAmount; if (timeBased) { healing *= Time.deltaTime; } } } // Apply healing if (healingValue != 0) { damageReceiver.Heal(healingValue, hit.point, healthModifierType, rootTransform); } } }