/// <summary> /// Listener of Damage Event /// </summary> /// <param name="hitInfo"></param> public virtual void OnDamageHit(AIHitInfo hitInfo) { Damage damage = new Damage(hitInfo.aiattackObject.damage); damage.sender = transform; damage.receiver = hitInfo.targetCollider.transform; if (this.attackName != string.Empty) { damage.attackName = this.attackName; } /// Calc damage with multiplier /// and Call ApplyDamage of attackObject damage.damageValue *= damageMultiplier > 1 ? damageMultiplier : 1; hitInfo.aiattackObject.ApplyDamage(hitInfo.aiHitBox, hitInfo.targetCollider, damage); onDamageHit.Invoke(hitInfo); }
public void PlayHitEffects(AIHitInfo hitInfo) { if (hitInfo.targetCollider != null && hitInfo.targetCollider.tag.Equals("Player")) { var clip = attackHitSounds; var audioObj = Instantiate(audioSource, transform.position, transform.rotation) as GameObject; audioObj.GetComponent <AudioSource>().PlayOneShot(clip); } if (audioSource != null && hitSounds.Length > 0) { var clip = hitSounds[UnityEngine.Random.Range(0, hitSounds.Length)]; var audioObj = Instantiate(audioSource, transform.position, transform.rotation) as GameObject; audioObj.GetComponent <AudioSource>().PlayOneShot(clip); } }
public virtual void OnHit(AIHitBox hitBox, Collider other) { //Check first contition for hit if (canApplyDamage && !targetColliders[hitBox].Contains(other.gameObject) && (aiManager != null && other.gameObject != aiManager.gameObject)) { var inDamage = false; if (aiManager == null) { aiManager = GetComponentInParent <AIManager>(); } //check if meleeManager exist and apply his hitProperties to this HitProperties _hitProperties = aiManager.hitProperties; /// Damage Conditions if ((_hitProperties.hitDamageTags.Contains(other.tag))) { inDamage = true; } if (inDamage) { ///add target collider in list to control frequency of hit him targetColliders[hitBox].Add(other.gameObject); AIHitInfo hitInfo = new AIHitInfo(this, hitBox, other, hitBox.transform.position); if (inDamage == true) { /// If meleeManager /// call onDamageHit to control damage values /// and meleemanager will call the ApplyDamage after to filter the damage /// if meleeManager is null /// The damage will be directly applied /// Finally the OnDamageHit event is called if (aiManager) { aiManager.OnDamageHit(hitInfo); } else { damage.sender = transform; ApplyDamage(hitBox, other, damage); } onDamageHit.Invoke(hitInfo); } } } }