private void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.CompareTag("bullet")) { gameObject.transform.DOKill(); int damage = other.gameObject.GetComponent <Bullet>().getDamage(); enemyModel.setLife(enemyModel.getLife() - damage); enemyModel.setHitted(true); if (enemyModel.getLife() <= 0) { Debug.Log(Math.Abs(other.transform.position.y - gameObject.transform.position.y)); if (Math.Abs(other.transform.position.y - gameObject.transform.position.y) > 0.4) { ServiceLocator.Instance.eventManager.Propagate(new PointEvent(ServiceLocator.Instance.gameConfig.headShotPoint)); Debug.Log("HEADSHOT"); } else { ServiceLocator.Instance.eventManager.Propagate(new PointEvent(ServiceLocator.Instance.gameConfig.normalShotPoint)); } Destroy(enemyCollider); enemyRigibody.freezeRotation = false; enemyRigibody.bodyType = RigidbodyType2D.Dynamic; enemyRigibody.AddTorque(enemyModel.getDeadTorque()); Vector2 a = other.gameObject.GetComponent <Rigidbody2D>().velocity; enemyRigibody.AddForce(new Vector2(100 * Math.Sign(a[0]), enemyModel.getDeadUpForce())); Destroy(gameObject, 1f); } Destroy(other.gameObject); } }
public void comprobateLife() { if (enemy.getLife() >= 1) { StartCoroutine(onBeat()); } else if (enemy.getLife() <= 0) { StartCoroutine(dead()); } }