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