Question by
unity_9NOShMI4jpX2ZA · Mar 30 at 03:39 AM ·
scripting problem
How do I choose a specific NPC Text within this script?
I am trying to have a multitude of characters and would like the text dialogue to be different with each one, however I can not select the text to display, how could I achieve this using the following script:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerInteraction : MonoBehaviour { private GameObject triggeringNpc; private bool triggering;
public GameObject npcText;
void Update()
{
if(triggering)
{
npcText.SetActive(true);
if(Input.GetKeyDown(KeyCode.E))
{
Destroy(triggeringNpc);
triggering = false;
}
}
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;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Any way to update a string array mid game?,Update the strings in a string array mid game? 1 Answer
Why is my Camera not rotating properly? 1 Answer
Saving doesn't work after Build 0 Answers
How can I avoid Input.GetKeyDown() being detected before it complete the iTween.MoveAdd() call? 2 Answers
Isometric Movent Issue 0 Answers