//Check if the player as collided with the object private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "Player") { //Get his life system script lifeSystemScript = collision.GetComponent <LifeSystem>(); //Check if he is not full life if (lifeSystemScript.Life < maxLife) { //Rise his life lifeSystemScript.RiseLife(); } //Instantiate the Poof Prefab and destroy itself Instantiate(poof, transform.position, Quaternion.identity); Destroy(gameObject.transform.parent.gameObject); } }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Player") { //If the Player isn't dashing and isn't colliding with the head collider... if (!playerDashing && !enemyHeadColliderScript.HeadBump) { if (!playerInhaling) { //...and he is not using the Inhale power, lower is life playerLifeSystem.LowerLife(); } else { //...and he is using the Inhale power, rise is life playerLifeSystem.RiseLife(); } } //Kill the enemy. Kill(); } }