Follow up solution for BUG. We can use a child object to trigger the attack animation which will solve the problem for most positions.
Body child object will have another
BoxCollider2D
and tag script DefenderBody
.
Lizard.cs
void OnTriggerEnter2D(Collider2D collider){
GameObject collidedGameObject = collider.gameObject;
if (!collidedGameObject.GetComponent<DefenderBody> ()) {
return;
}
animatorObject.SetBool ("isAttackingBool", true);
attackerObject.Attack (collidedGameObject.transform.parent.gameObject);
}
Fox.cs
void OnTriggerEnter2D(Collider2D collider){
GameObject collidedGameObject = collider.gameObject;
if (collidedGameObject.GetComponent<Defender> () && collidedGameObject.GetComponent<Stone>() ) {
animatorObject.SetTrigger ("isJumpingTrigger");
}
if (!collidedGameObject.GetComponent<DefenderBody> ()) {
return;
} else if(!collidedGameObject.transform.parent.GetComponent<Stone>()){
animatorObject.SetBool ("isAttackingBool", true);
attackerObject.Attack (collidedGameObject.transform.parent.gameObject);
}
}