using UnityEngine; using TMPro; public class ChangeArea : MonoBehaviour { bool playerInZone = false; public TextMeshProUGUI promptText; //So I can add my ui text in the inspector private GameObject player; public Transform playerTarget; //Where the player will go public Transform cameraTarget; //Where the camera will go // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { promptText.enabled = false; //Hide my ui text at the start } // Update is called once per frame void Update() { if (playerInZone && Input.GetKeyDown(KeyCode.E)) { player.transform.position = playerTarget.position; //Move player to next area Camera.main.transform.position = cameraTarget.position; //Move camera to next area } } void OnTriggerEnter2D(Collider2D other) //Run this method when the player walks into the transition zone { if (other.CompareTag("Player")) { playerInZone = true; player = other.gameObject; if (promptText != null) //Show ui text { promptText.enabled = true; } } } void OnTriggerExit2D(Collider2D other) //Run this method when the player walks out of the transition zone { if (other.CompareTag("Player")) { playerInZone = false; player = null; if (promptText != null) //Hide ui text { promptText.enabled = false; } } } }