public void InflictDamageInArea(float damage, Vector3 center, LayerMask layers, QueryTriggerInteraction interaction, GameObject owner) { HashSet <InteractionDamageSelf> uniqueDamageables = new HashSet <InteractionDamageSelf>(); // Create a collection of unique health components that would be damaged in the area of effect (in order to avoid damaging a same entity multiple times) Collider[] affectedColliders = Physics.OverlapSphere(center, areaOfEffectDistance, layers, interaction); foreach (var coll in affectedColliders) { InteractionDamageSelf damageable = coll.GetComponent <InteractionDamageSelf>(); if (damageable) { if (uniqueDamageables.Contains(damageable)) { uniqueDamageables.Add(damageable); } } } // Apply damages with distance falloff foreach (InteractionDamageSelf uniqueDamageable in uniqueDamageables) { float distance = Vector3.Distance(uniqueDamageable.transform.position, transform.position); uniqueDamageable.iteractiableBase.Interact(owner); } }
void OnHit(Collider collider) { // point damage InteractionDamageSelf damageable = collider.GetComponent <InteractionDamageSelf>(); if (damageable) { damageable.iteractiableBase.Interact(gameObject); } // // impact vfx // if (impactVFX) // { // GameObject impactVFXInstance = Instantiate(impactVFX, point + (normal * impactVFXSpawnOffset), Quaternion.LookRotation(normal)); // if (impactVFXLifetime > 0) // { // Destroy(impactVFXInstance.gameObject, impactVFXLifetime); // } // } // // impact sfx // if (impactSFXClip) // { // AudioUtility.CreateSFX(impactSFXClip, point, AudioUtility.AudioGroups.Impact, 1f, 3f); // } }
void OnHit(Collider collider) { // point damage InteractionDamageSelf damageable = collider.GetComponent <InteractionDamageSelf>(); if (damageable) { damageable.iteractiableBase.Interact(gameObject); CharacterStatsController stats = collider.GetComponent <CharacterStatsController>(); print("HIT!"); if (stats != null) { print("Slowed!"); stats.moveSpeed.AddTemporaryModifier(slowAmount, slowDuration); } } // // impact vfx // if (impactVFX) // { // GameObject impactVFXInstance = Instantiate(impactVFX, point + (normal * impactVFXSpawnOffset), Quaternion.LookRotation(normal)); // if (impactVFXLifetime > 0) // { // Destroy(impactVFXInstance.gameObject, impactVFXLifetime); // } // } // // impact sfx // if (impactSFXClip) // { // AudioUtility.CreateSFX(impactSFXClip, point, AudioUtility.AudioGroups.Impact, 1f, 3f); // } Destroy(this.gameObject); }
private void OnHit(Collider collider) { // point damage InteractionDamageSelf damageable = collider.GetComponent <InteractionDamageSelf>(); if (damageable) { damageable.iteractiableBase.Interact(gameObject); CharacterStatsController stats = collider.GetComponent <CharacterStatsController>(); if (stats != null) { stats.moveSpeed.AddTemporaryModifier(slowAmount, slowDuration); } } print(string.Format("hit : {0}", collider.name)); Destroy(this.gameObject); }