Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- public class Sign : MonoBehaviour
- {
- public GameObject dialogBox;
- public Text dialogText;
- public string dialog;
- public bool playerInRange;
- private void OnTriggerEnter2D(Collider2D other) {
- if (other.CompareTag("Player")) {
- playerInRange=true;
- }
- }
- private void OnTriggerExit2D(Collider2D other) {
- if (other.CompareTag("Player")) {
- playerInRange=false;
- dialogBox.SetActive(false);
- }
- }
- private void Update() {
- if (Input.GetKeyDown("Interact") && playerInRange) {
- if (dialogBox.activeInHierarchy) {
- dialogBox.SetActive(false);
- } else {
- dialogBox.SetActive(true);
- dialogText.Text = dialog;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement