//will occur when player interacts with Enemy object void OnTriggerEnter2D(Collider2D collide) { if (collide.gameObject.tag == "hurtbox") { //to kill enemy, we tell the enemy script TheEnemy script = collide.gameObject.GetComponentInParent <TheEnemy>(); script.Die(); } if (collide.gameObject.tag == "hurtbox2") { TheBoss script = collide.gameObject.GetComponentInParent <TheBoss>(); script.Oof(); Debug.Log("oof"); } if (collide.gameObject.tag == "hitbox") { health--; //player takes damage } if (collide.gameObject.tag == "checkPoint") { SpawnPoint = collide.transform; GameManager.UpdateSpawn(collide.transform); Debug.Log("2"); } if (collide.gameObject.tag == "Finish") { SceneManager.LoadScene(newscene); } }
public void OnTriggerEnter2D(Collider2D collision) { //if this object touches an enemy's hurtbox if (collision.gameObject.tag == "hurtbox") { //to kill enemy, we call enemy script Die() function to kill object TheEnemy script = collision.gameObject.GetComponentInParent <TheEnemy>(); script.Die(); } }
//will occur when player interacts with Enemy object void OnTriggerEnter2D(Collider2D collide) { if (collide.gameObject.tag == "hurtbox") { //to kill enemy, we tell the enemy script TheEnemy script = collide.gameObject.GetComponentInParent <TheEnemy>(); script.Die(); } if (collide.gameObject.tag == "hitbox") { health--; //player takes damage } if (collide.gameObject.tag == "checkPoint") { SpawnPoint = collide.transform; GameManager.UpdateSpawn(collide.transform); } }