//Jimmy Vegas Unity Tutorial //This script is for your NPC using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.AI; public class NPCChoice : MonoBehaviour { public float TheDistance; public GameObject ActionDisplay; public GameObject ActionText; public GameObject ExtraCursor; public GameObject subText; public GameObject subBox; public GameObject thePlayer; void Update() { TheDistance = PlayerCasting.DistanceFromTarget; } void OnMouseOver() { if (TheDistance <= 3) { ActionDisplay.SetActive(true); ActionText.GetComponent().text = "Talk"; ActionText.SetActive(true); ExtraCursor.SetActive(true); } else { ActionDisplay.SetActive(false); ActionText.SetActive(false); ExtraCursor.SetActive(false); } if (Input.GetButtonDown("Action")) { if (TheDistance <= 3) { this.transform.LookAt(new Vector3(thePlayer.transform.position.x, this.transform.position.y, thePlayer.transform.position.z)); this.GetComponent().Play("Idle"); this.GetComponent().enabled = false; this.GetComponent().enabled = false; subBox.SetActive(true); subText.GetComponent().text = "Hello there, how can I help you?"; this.GetComponent().enabled = false; ActionDisplay.SetActive(false); ActionText.SetActive(false); ExtraCursor.SetActive(false); StartCoroutine(ResetChat()); } } } void OnMouseExit() //this is when the mouse moves away { ActionDisplay.SetActive(false); ActionText.SetActive(false); ExtraCursor.SetActive(false); } IEnumerator ResetChat() { yield return new WaitForSeconds(2.5f); subBox.SetActive(false); this.GetComponent().enabled = true; subText.GetComponent().text = ""; this.GetComponent().Play("Walking"); this.GetComponent().enabled = true; this.GetComponent().enabled = true; } }