public void isAttackedBy(CarStatus attacker, float weaponModifier = 1) { // check attacker abilities(poison, liseSteal, stun) // check self ability(reflect == true) float reflectedDamage = 0;//give attacker damage(if has reflect ability) float receivedDamage = damageValue(attacker, this, weaponModifier); //Debug.Log("receivedDamage = " + receivedDamage); CarStatus negativeEffectReciever = this; if (reflectAbility) { receivedDamage = receivedDamage / 2; reflectedDamage = receivedDamage; negativeEffectReciever = attacker; } if (attacker != null) { if (attacker.poisonAbility > 0) { negativeEffectReciever.isPoisoned = true; negativeEffectReciever.poisonTimer = 0; negativeEffectReciever.poisonAttacker = this; negativeEffectReciever.poisonDPS = attacker.poisonAbility; } if (attacker.stunAbility) { negativeEffectReciever.stunnedTimer = 0; negativeEffectReciever.isStunned = true; Transform spawnTrans = negativeEffectReciever.transform; GameObject stunObj = Instantiate(stunAnime, spawnTrans.position + new Vector3(0, 1.5f, 0), spawnTrans.rotation, spawnTrans); stunObj.GetComponent <StunningStar>().setLifetime(negativeEffectReciever.stunningTime); } if (reflectedDamage > 0) { //reflecting damage has no critical chance and cannot trigger other special effect(stun, poison and reflect) attacker.decreaseHP(reflectedDamage); } } decreaseHP(receivedDamage); }