Reputation: 43
I can easily access this String Array from my main script (RPGDialogueManager.cs) and the value was displaying normally but when I try to access this array to my other script (RPGDialogueHolder.cs), change its value, and change the "lineNum" back to 0, it won't display the value. It just glitches (it display the value of index 1, but it quickly revert to the default line which is "Hey you, What makes you go here?")
Note: The dialogueLines in RPGDialogueHolder.cs is different from dialogueLines in RPGDialogueManager.cs. Both string arrays has different values from each other
RPGDialogueManager.cs
void Start () {
dialogueBox.SetActive(true);
directionalButtons.SetActive(false);
dialogueText.text = "In the middle of the day, this two young adults volunteer to help and leads me to their town";
nextButton.onClick.AddListener(DialogueLines);
}
public void DialogueLines()
{
if (lineNum >= dialogueLines.Length)
{
dialogueBox.SetActive(false);
directionalButtons.SetActive(true);
lineNum = 0;
}
dialogueText.text = dialogueLines[lineNum];
lineNum++;
}
public void ShowDialogue()
{
dialogueBox.SetActive(true);
directionalButtons.SetActive(false);
}
RPGDialogueHolder.cs
void OnTriggerStay2D(Collider2D collider2D)
{
if (collider2D.gameObject.name == "Player")
{
// dialogueManager.dialogueText.text = dialogue;
dialogueManager.dialogueText.text = "Hey you, What makes you go here?";
dialogueManager.dialogueLines = dialogueLines;
dialogueManager.lineNum = 0;
aButton.onClick.AddListener(dialogueManager.ShowDialogue);
}
}
Upvotes: 0
Views: 87
Reputation: 1546
OnTriggerStay2D
is called every frame if your player is inside the trigger. So you are essentially resetting your dialogue to the Hey you,...
one each frame.
Try changing you callback from OnTriggerStay2D
to OnTriggerEnter2D
or use some other approach for dialogues
Upvotes: 2