/// <summary> /// OnTriggerExit is called when the Collider other has stopped touching the trigger /// </summary> /// <param name="other"></param> private void OnTriggerExit(Collider other) { // ----- Ground Collision ----- // If the player is no longer touching the ground then they are in the air if (other.gameObject.CompareTag("Ground")) { isGrounded = false; } // ----- Starting Teleporter Collision ----- // If the player is no longer touching the starting teleporter then they are in the air if (other.gameObject.CompareTag("Respawn")) { isGrounded = false; } // ----- Box Collision ----- // If the player is no longer touching the box then they are in the air if (other.gameObject.CompareTag("Box")) { isOnBox = false; } // ----- Moving Platform Collision ----- // If the player is no longer touching a moving platform then they are in the air if (other.gameObject.CompareTag("MovingPlatform")) { isGrounded = false; transform.parent = null; } // ----- Dropping Platform Collision ----- // If the player is no longer touching the droping platform then they are in the air if (other.gameObject.CompareTag("DroppingPlatform")) { isGrounded = false; droppingPlatform = null; } }
/// <summary> /// OnTriggerEnter is called when the collider other enters the trigger /// </summary> /// <param name="other"></param> private void OnTriggerEnter(Collider other) { // ----- Box Collision ----- // If the player jumps on the box if (other.gameObject.CompareTag("Box") && falling) { // Increase score by 1 playerCoins++; // Destroy box Destroy(other.gameObject); // Make player bounce up velocity.y = 0; velocity.y += 8.0f; } // ----- Coin Collision ----- // When player collects a coin if (other.gameObject.CompareTag("Coin")) { // Increase score by 1 and destroy coin playerCoins++; Destroy(other.gameObject); } // ----- Lightning Collision ----- // When the player touches the lightning of an electric fence if (other.gameObject.CompareTag("Lightning")) { // The player is dead isDead = true; } // ---- Starting teleporter ----- // If the player is on top of the starting teleporter, player can then jump if they wanted to if (other.gameObject.CompareTag("Respawn")) { isGrounded = true; velocity.y = 0; } // ----- Finish Collision ----- // If the player touches the finishing teleporter, go to the victory screen if (other.gameObject.CompareTag("Finish")) { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1); } // ----- Moving Platform Collision ----- // If the player is on a moving platform, if (other.gameObject.CompareTag("MovingPlatform")) { // Make the player a child of the moving platform, to allow them to move with the platform // and allow them to jump off the platform isGrounded = true; transform.parent = other.transform; } // ----- Dropping Platform Collision ----- // If the player touches the dropping platform, if (other.gameObject.CompareTag("DroppingPlatform")) { // Start the timer for the platform. isGrounded = true; droppingPlatform = other.gameObject.GetComponent <DroppingPlatformScript>(); droppingPlatform.playerOnPlatform = true; } }