Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by YOLO_cakes · Apr 20, 2017 at 06:27 PM · c#2duitextdialogue

Multiple NPCs

Hey all! I have been following a YouTube tutorial on how to create text boxes for NPC's since it has been a while and have run into a problem. When I talk to the first NPC it all works correctly however, when I approach the second NPC no text box occurs. Here are the scripts that link together along with a link to the tutorial I followed.

Also I have attached the scripts correctly since I just copy and pasted the first NPC to test this, the dialog is different so it should show up except, well it doesn't. Anyway thanks for taking the time to look in advance!

Script that contains the dialog for the NPC (attached to each NPC.)

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class dialogHolder : MonoBehaviour {
 
     public string dialogue;
     private DialogueManager dMan;
     public string[] dialogueLines;
 
     // Use this for initialization
     void Start ()
     {
         dMan = FindObjectOfType<DialogueManager>();
     }
     
     // Update is called once per frame
     void Update () {
         
     }
 
     void OnTriggerEnter2D(Collider2D other)
     {
         if(other.gameObject.name == "Player")
         {
             //dMan.ShowText(dialogue);
 
         if (!dMan.dialogActive)
             {
                 dMan.dialogLines = dialogueLines;
                 dMan.currentLine = 0;
                 dMan.ShowDialogue();
             }
         } 
     }
 }
 

Dialog manager script (attached to canvas)

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class DialogueManager : MonoBehaviour {
 
     public GameObject dBox;
     public Text dText;
     public bool dialogActive;
     public string[] dialogLines;
     public int currentLine;
     private Player thePlayer;
 
     // Use this for initialization
     void Start () {
 
         dBox.SetActive(false);
         thePlayer = FindObjectOfType<Player>();
 
     }
     
     // Update is called once per frame
     void Update ()
     {
         if (dialogActive && Input.GetKeyDown(KeyCode.Return))
         {
             //dBox.SetActive(false);
             currentLine++;
         }
         if (currentLine >= dialogLines.Length)
         {
             dBox.SetActive(false);
 
             currentLine = 0;
             thePlayer.canMove = true;
         }
         dText.text = dialogLines[currentLine];
     }
 
     public void ShowText(string dialogue)
     {
         dialogActive = true;
         dBox.SetActive(true);
         dText.text = dialogue;
     }
 
     public void ShowDialogue()
     {
         dialogActive = true;
         dBox.SetActive(true);
         thePlayer.canMove = false;
     }
 }
 

Tutorial Link https://youtu.be/cVS9-nPmzGg

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by bobisgod234 · Apr 21, 2017 at 12:03 AM

The variable dialogActive is never set back to false, and your dialogHolder class wont call ShowDialogue() unless it is.

I have never seen this tutorial, but I assume you aresupposed to set it false when you disable the dialoge box:

          if (currentLine >= dialogLines.Length)
          {
              dBox.SetActive(false);
              dialogActive = false;
              currentLine = 0;
              thePlayer.canMove = true;
          }
Comment
Add comment · Show 1 · Share
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
avatar image YOLO_cakes · Apr 22, 2017 at 03:04 PM 0
Share

Thanks for taking the time to read through my code, you was correct. After inserting your code it is working perfectly, thank you!

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.

Follow this Question

Answers Answers and Comments

7 People are following this question.

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

Related Questions

How do i make a BattleLog? 0 Answers

How to change a notepad file for another notepad file? 1 Answer

How to display UI Text on GameObject in script? 0 Answers

My text is invisible if I put it under the Content object under a Scroll View 1 Answer

How do I call an DontDestroyOnLoad function on UI text 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges