How to reset NPC dialogue?
I am working on a project that allows the player to move around and interact with 3 NPCs. So far the player has the ability to move around and approach the NPCs (approaching them will trigger text to appear on the screen that says "Press 'E' to Talk" ). The problem is when I approach an NPC (which triggers the text "Press 'E' to Talk") and when 'E' is pressed I can get a response from the NPCs but it is only one response currently and I do not know how to reset the text so I can interact with them many times repeatedly. For example, when I approach them and press 'E' I get a text response but when I approach other NPCs or even the same NPC the text that was displayed previously shows up again instead of "Press 'E' to Talk". Is there a way to reset the text so that I can interact with 3 NPCs multiple times and have different dialogue for each? I have included some examples of the scripts that I am using to help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Player : MonoBehaviour
{
private GameObject triggeringNPC;
private bool triggering;
public GameObject NPCText;
void Update()
{
if (triggering)
{
NPCText.SetActive (true);
}
else
{
NPCText.SetActive (false);
}
}
void OnTriggerEnter (Collider other)
{
if (other.tag == "NPC")
{
triggering = true;
triggeringNPC = other.gameObject;
}
}
void OnTriggerExit (Collider other)
{
if (other.tag == "NPC")
{
triggering = false;
triggeringNPC = null;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class NPCDialogue : MonoBehaviour
{
[SerializeField]
private Text Dialogue = null;
string NPC1 = "I am NPC1";
string NPC2 = "I am NPC2";
string NPC3 = "I am NPC3";
void Update ()
{
if(Input.GetKeyDown(KeyCode.E))
{
Dialogue.text = NPC1;
}
}
}
Your answer
Follow this Question
Related Questions
Best Practice For Storing RPG Dialogue? 1 Answer
Text Mesh pro won't show certain characters 1 Answer
Text won't properly update in Unity Bolt 1 Answer
Unity 5 - Does anyone know how to scale the text in the UI? 1 Answer
Resizing font by scale according to screen size, (More complicated than you might think) 1 Answer