When an attacker is attacking a defender and we place a new one behind it, it calls the `OnTriggerEnter2D’ which passes the new defender as the selected target. The attacker destroys the new defender and proceeds ahead without destroying the former defender.
Fox/Lizard.cs
void OnTriggerEnter2D(Collider2D collider){
GameObject collidedGameObject = collider.gameObject;
if (!collidedGameObject.GetComponent<Defender> ()) {
return;
}
if (collidedGameObject.GetComponent<Stone> ()) {
animatorObject.SetTrigger ("isJumpingTrigger");
} else {
animatorObject.SetBool ("isAttackingBool", true);
attackerObject.Attack (collidedGameObject);
}
}
Attacker.cs
public void Attack(GameObject targetGameObject){
currentTargetObject = targetGameObject;
}
How to fix this?