//反复计算飞镖伤害问题 public void OnTriggerEnter(Collider other) { if (other.transform.root.gameObject.layer == LayerMask.NameToLayer("Scene")) { SceneItemAgent it = other.GetComponentInParent <SceneItemAgent>(); if (it != null) { //Debug.Log("dart attack sceneitemagent"); if (recordList.Find(m => m.sceneitem.Equals(it)) != null) { return; } it.OnDamage(owner, _attack); DamageRecord record = new DamageRecord(); record.target = null; record.sceneitem = it; record.tick = 0.2f; recordList.Add(record); } GameObject.Destroy(gameObject); } else { MeteorUnit unit = other.GetComponentInParent <MeteorUnit>(); if (unit == null) { return; } //同队忽略攻击 if (unit.SameCamp(owner)) { return; } //部分关卡角色无阵营 if (unit == owner) { return; } //反复进入.各个骨骼,不同的受击盒. if (recordList.Find(m => m.target.Equals(unit)) != null) { return; } //Debug.LogError("dart attack start"); unit.OnAttack(owner, _attack); DamageRecord record = new DamageRecord(); record.target = unit; record.tick = 0.2f; recordList.Add(record); GameObject.Destroy(gameObject); //Debug.LogError("dart attack end"); } }
void DetectDamage(Collider other) { if (Owner == null) { if (Attacker == null) return; //角色发射出的特效攻击盒 SceneItemAgent target = other.gameObject.GetComponentInParent<SceneItemAgent>(); if (target != null) { if (Attacker.ExistDamage(target)) return; Attacker.Attack(target); target.OnDamage(Attacker.mOwner, AttackDef); } else { MeteorUnit unit = other.gameObject.GetComponentInParent<MeteorUnit>(); if (unit != null) { if (Attacker.mOwner == unit) return; if (Attacker.mOwner.SameCamp(unit)) return; if (Attacker.ExistDamage(unit)) return; //Debug.LogError("name:" + name + " hit other:" + other.name); Attacker.Attack(unit); unit.OnAttack(Attacker.mOwner, AttackDef == null ? Attacker.mOwner.CurrentDamage : AttackDef); } } return; } //角色身体上的攻击盒/武器上的攻击盒 SceneItemAgent agent = other.gameObject.GetComponentInParent<SceneItemAgent>(); if (agent != null) { if (Owner.ExistDamage(agent)) return; Owner.Attack(agent); agent.OnDamage(Owner, AttackDef); } else { MeteorUnit unit = other.gameObject.GetComponentInParent<MeteorUnit>(); if (unit != null) { if (Owner == unit) return; if (Owner.SameCamp(unit)) return; if (Owner.ExistDamage(unit)) return; //Debug.LogError("name:" + name + " hit other:" + other.name); Owner.Attack(unit); unit.OnAttack(Owner, AttackDef == null ? Owner.CurrentDamage : AttackDef); } } }