void OnTriggerEnter2D(Collider2D other) { // get tag of object colliding into string name = other.gameObject.tag; // check if bullet collided into player One if (name == "PlayerOne") { // decrease health and destroy bullet P1HealthScript.decreaseHealth(); Destroy(gameObject); // check if player two is dead if (P1HealthScript.currentHealth <= 0) { // destroy player two and restart game Destroy(other.gameObject); SceneManager.LoadScene(SceneManager.GetActiveScene().name); } } // check if bullet collided into a wall if (name == "Obstacle") { // destroy bullet Destroy(gameObject); } }
void OnTriggerEnter2D(Collider2D other) { // get tag of object colliding into string name = other.gameObject.tag; // check if sword collided into player ones bullet if (name == "P1Bullet") { // refect player ones bullet Instantiate(bullet, transform.position, PlayerTwo.bulletRotation); // destroy player ones bullet Destroy(other.gameObject); } // check if sword has collided with player one if (name == "PlayerOne") { // decrease player ones health P1HealthScript.decreaseHealth(); // check if player one has died if (P1HealthScript.currentHealth <= 0) { // detroy player one and restart game Destroy(other.gameObject); SceneManager.LoadScene(SceneManager.GetActiveScene().name); } } }