• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Rin_Vael · Jun 02, 2017 at 10:49 PM · uitextnpcdialogue

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;
         }
     }
 
 }
 
 
 



Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

146 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Best Practice For Storing RPG Dialogue? 1 Answer

MissingReferenceException: The object of type 'Text' has been destroyed but you are still trying to access it. 5 Answers

Text letter-by-letter dialogue overflow 1 Answer

how do i change max size value of text component unity? 1 Answer

Making a growing number 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges