I have been debugging the crap out of this dialogue system, but still getting a classic error:
IndexOutOfRangeException: Index was outside the bounds of the array.
It’s really basic, so I feel like I might just be driving myself crazy and overlooking something. Here is the script in question:
if (canTalk && (PlayerController.instance.player.GetButtonUp("Fire") || PlayerController.instance.player.GetButtonUp("Dodge")) && DialogueManager.instance.isChatting)
{
dCounter++;
if (DialogueManager.instance.isChatting)
{
if (dialogueSelection == 0)
{
DialogueManager.instance.dialogueText.text = dialogueLine[dCounter];
}
if (dialogueSelection == 1)
{
DialogueManager.instance.dialogueText.text = dialogueLineB[dCounter];
}
if (dialogueSelection == 2)
{
DialogueManager.instance.dialogueText.text = dialogueLineC[dCounter];
}
}
AudioManager.instance.PlaySFX(dialogueSound);
}
In this case dialogueSelection == 0, so the error is happening at:
DialogueManager.instance.dialogueText.text = dialogueLine[dCounter];
So wth am I doing wrong here? Oh and I should note the dialogue is being displayed as long as the player is triggering a collider:
private void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
AudioManager.instance.PlaySFX(dialogueStartSound);
DialogueManager.instance.isChatting = true;
if (dialogueSelection == 0)
{
DialogueManager.instance.dialogueText.text = dialogueLine[dCounter];
}
if (dialogueSelection == 1)
{
DialogueManager.instance.dialogueText.text = dialogueLineB[dCounter];
}
if (dialogueSelection == 2)
{
DialogueManager.instance.dialogueText.text = dialogueLineC[dCounter];
}
DialogueManager.instance.dialogueContainer.SetActive(true);
PlayerController.instance.canWalk = false;
PlayerController.instance.cannotDodge = true;
PlayerController.instance.rangedArm.SetActive(false);
PlayerController.instance.meleeArm.SetActive(false);
canTalk = true;
}
}