public void OnTriggerEnter2D(Collider2D collision) { IEnemyDamage enemyDmg = null; if (collision.CompareTag("Enemy")) { Debug.Log("COLLISION NAME " + collision.name + " " + collision.gameObject.name); /* if (collision.name.Equals("Spirit Boxer")) * enemyDmg = collision.GetComponent<IEnemyDamage>(); * * if (enemyDmg != null) * { * enemyDmg.TakeDamage(damage); * }*/ enemyDmg = collision.gameObject.GetComponent <IEnemyDamage>(); enemyDmg.TakeDamage(damage); if (!collision.name.Equals("Player") && !collision.tag.Equals("Projectile")) { rb.velocity = transform.right; animator.SetBool("isDestroyed", true); Destroy(gameObject, 0.15f); } } }
// Use this for initialization void Start() { agent = GetComponent <NavMeshAgent>(); agent.SetDestination(targetPos); enemy = GetComponent <EnemyObejct>(); enemyDamage = enemy as IEnemyDamage; }
void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.CompareTag("Hitbox")) { IEnemyDamage script = collision.transform.parent.parent.GetComponent <IEnemyDamage>(); //TODO make interface for AI and damage scripts; (int AttackID, int Damage)Tuple = script.MakeDamage(); TakeDamage(Tuple.Damage); CheckForSpecialAttacks(script.GetGameObject().name.Replace(" ", "") + Tuple.AttackID, collision.transform); } }
private void OnCollisionEnter2D(Collision2D other) { if (mode == Mode.Attacking || mode == Mode.Dying) { return; } var hit = other.gameObject.GetComponent <IEnemyDamage>(); if (hit == null) { return; } AttackMode(); currentAttacked = hit; rb.constraints = RigidbodyConstraints2D.FreezeAll; StartCoroutine(DelayMovement()); }
private void OnCollisionExit2D(Collision2D other) { if (mode == Mode.Dying) { return; } if (other.gameObject.GetComponent <IEnemyDamage>() != currentAttacked) { return; } if (currentAttacked as Sheep.Sheep != null && !other.gameObject.activeInHierarchy) { Die(); return; } currentAttacked = null; WalkMode(); }