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 /
  • Help Room /
avatar image
0
Question by Cammuny · Nov 15, 2015 at 08:13 AM · textbuttonsforeachdialogueloops

Dialogue Skipping Issues?

Hey guys, I created this dialogue script with a simple Branch Dialogue layout of Name, Text and Button Answers. But I'm having issues where it decides to skip a branch and answer it by itself randomly every time. I'm thinking maybe the foreach loop is picking answers by itself somehow but I'm really stuck on this. Any feedback would be greatly appreciated. I have double checked that everything is sorted out in the scene as well.

This is for each Branch in the dialogue.

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class BranchDialogue : MonoBehaviour 
 {
     public string answerToPreviousQuestion;
     public MentalStateTypes mentalStateType;
     public int stateAmount;
     public bool isKaia;
     public string name;
     public string question;
     public BranchDialogue[] answers;
 
     public virtual void Action()
     {
         //Debug.Log ("Action");
     }
 }

And this is the Branch Dialogue manager which updates the text, and picks how many buttons appear and disappear and changing the answers.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class BranchDialogueManager : MonoBehaviour 
 {
     public static BranchDialogueManager instance;
 
     public BranchDialogue myText;
     public PlayerControl playerCtrl;
     public ClickAndPoint clickAndPoint;
     public GameObject bluePanel;
     public Button[] myAnswerButtons;
     public Transform kaia;
     public Transform lirien;
     public EnableOnActive highlightButton;
     public GameObject pressA;
 
 
     bool stopsPlayer;
     GameObject currentTrigger;
 
     void Awake()
     {
         instance = this;
     }
 
     public void StartBranch(GameObject trig, bool stopPlayer)
     {
 
         print (MentalStateManager.instance.MentalStateDict [MentalStateTypes.Neutral]);
         stopsPlayer = stopPlayer;
         currentTrigger = trig;
         BlueDialogue.instance.currentText = 0;
         highlightButton.OnEnable ();
 
         if (stopsPlayer) 
         {
             //THe UI Text box
             BlueDialogue.instance.myTextObject.gameObject.SetActive(true);
 
             //Our dialogue branches
             //BlueDialogue.instance.myDialogue = myText.dialogue;
 
             BlueDialogue.instance.name.text = myText.name;
             BlueDialogue.instance.myTextObject.text = myText.question;
 
             BranchDialogueManager.instance.SetButtons();
 
             playerCtrl.enabled = false;
             //clickAndPoint.enabled = false;
 
 
 
 
         } 
         else 
         {
             if(myText.isKaia)
             {
                 //THe UI Text box
                 BlueDialogue.instance.kaiaText.text = "";
 
                 BlueDialogue.instance.kaiaText.gameObject.SetActive(true);
                 StartCoroutine(UpdateConversationTextDelay(myText.question,true));
 
                 BlueDialogue.instance.lirienText.gameObject.SetActive(false);
 
             }
             else
             {
                 //THe UI Text box
                 BlueDialogue.instance.lirienText.text = "";
                 BlueDialogue.instance.lirienText.gameObject.SetActive(true);
                 StartCoroutine(UpdateConversationTextDelay(myText.question,false));
 
                 BlueDialogue.instance.kaiaText.gameObject.SetActive(false);
 
             }
             StartCoroutine(TextTimer());
         }
         //anim.SetTrigger ("Idle");
         
         //Assign Values for text.
         myText.Action();
     }
 
     IEnumerator UpdateConversationTextDelay(string text,bool isKaia)
     {
         yield return new WaitForEndOfFrame ();
         yield return new WaitForEndOfFrame ();
         if(isKaia)
             BlueDialogue.instance.kaiaText.text = text;
         else
             BlueDialogue.instance.lirienText.text = text;
     }
 
     IEnumerator TextTimer()
     {
         yield return new WaitForSeconds (3.5f);
         UpdateMyText (0);
         yield break;
     }
 
     public void UpdateMyText(int answerNum)
     {
         //print (MentalStateManager.instance.MentalStateDict [MentalStateTypes.Neutral]);
         if (myText.answers.Length == 0)
             return;
         
         //Assign our new branch.
         myText = myText.answers[answerNum];
 
         myText.Action();
 
         highlightButton.OnEnable ();
         
         Debug.Log(myText.mentalStateType);
 
         
         Debug.Log(myText);
         
 
         
         if (stopsPlayer) 
         {
             MentalStateManager.instance.MentalStateChange(myText.mentalStateType, myText.stateAmount);
             
             BlueDialogue.instance.name.text = myText.name;
             BlueDialogue.instance.myTextObject.text = myText.question;
 
             SetButtons();
         } 
         else 
         {
             if(myText.isKaia)
             {
                 //THe UI Text box
                 BlueDialogue.instance.kaiaText.text = "";
                 
                 BlueDialogue.instance.kaiaText.gameObject.SetActive(true);
                 StartCoroutine(UpdateConversationTextDelay(myText.question, true));
                 
                 BlueDialogue.instance.lirienText.gameObject.SetActive(false);
                 
             }
             else
             {
                 //THe UI Text box
                 BlueDialogue.instance.lirienText.text = "";
                 BlueDialogue.instance.lirienText.gameObject.SetActive(true);
                 StartCoroutine(UpdateConversationTextDelay(myText.question, false));
                 
                 BlueDialogue.instance.kaiaText.gameObject.SetActive(false);
                 
             }
             StartCoroutine(TextTimer());
         }
         
         //KaiLeeDialogue.instance.cantTalk = true;
     }
     
     IEnumerator EndDialogue()
     {
         
         yield return new WaitForSeconds (0);
         playerCtrl.enabled = true;
         //clickAndPoint.enabled = true;
         myText.Action();
         BlueDialogue.instance.myTextObject.gameObject.SetActive(false);
         BlueDialogue.instance.lirienText.gameObject.SetActive(false);
         BlueDialogue.instance.kaiaText.gameObject.SetActive(false);
         bluePanel.gameObject.SetActive (false);
         //Destroy (currentTrigger);
         highlightButton.OnEnable ();
 
         
     }
     
     public void SetButtons()
     {
 
         //ACtivate the panel
         bluePanel.gameObject.SetActive (true);
 
         //Refill text for answers
         int num = 0;
         
         //Turn off buttons/answers
         foreach(Button b in myAnswerButtons)
         {
             b.gameObject.SetActive(false);
         }
         if(myText.answers.Length > 0)
         {
             foreach(BranchDialogue br in myText.answers)
             {
                 myAnswerButtons[num].gameObject.SetActive(true);
                 myAnswerButtons[num].GetComponentInChildren<Text>().text = br.answerToPreviousQuestion;
                 
                 num ++;
             }
         }
         else
         {
             //Insert fade and give back control here.
             
             StartCoroutine(EndDialogue());
             
         }
     }
 }

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.

Follow this Question

Answers Answers and Comments

33 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

Related Questions

Who to connect the Character Dialogue to a click event 0 Answers

instancing several buttons with different text 0 Answers

Dialogue not displaying next sentence 0 Answers

Calling functions that needs to be on update() 1 Answer

Inserting specific words into descriptions stored in XML 0 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