FGTE6003: Final Major Project - Timeleap Help

OutOfWorldSensor.cs

Description

This script is used to check if the player has fallen out of the world.

Script

using UnityEngine; using UnityEngine.SceneManagement; namespace Environment { public class OutOfWorldSensor : MonoBehaviour { private void OnTriggerEnter(Collider other) { if (!other.transform.parent.gameObject.CompareTag("Player")) return; SceneManager.LoadSceneAsync("deathScene"); } private void OnTriggerExit(Collider other) { if (!other.transform.parent.gameObject.CompareTag("Player")) return; SceneManager.LoadSceneAsync("deathScene"); } private void OnTriggerStay(Collider other) { if (!other.transform.parent.gameObject.CompareTag("Player")) return; SceneManager.LoadSceneAsync("deathScene"); } } }

Private Methods

OnTriggerEnter()

Checks if the collided object is the player. If it is, then load the death scene.

OnTriggerExit()

Checks if the collided object is the player. If it is, then load the death scene.

OnTriggerStay()

Checks if the collided object is the player. If it is, then load the death scene.

Last modified: 30 April 2024