I get this error in my code, "
IndexOutOfRangeException: Index was outside the bounds of the array.
DialogueManager.Update () (at Assets/Scripts/DialogueManager.cs:41)“.
and i have no idea why, iv’e checked other forums on this but i cant figure it out. the error is on line 41 which is this"dText.text = dialogLines[currentLine];”.my script is this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DialogueManager : MonoBehaviour {
public GameObject dBox;
public Text dText;
public bool dialogueActive;
public string[ ] dialogLines;
public int currentLine;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (dialogueActive && Input.GetKeyDown(KeyCode.Q))
{
//dBox.SetActive(false);
//dialogueActive = false;
currentLine++;
}
if(currentLine >= dialogLines.Length)
{
dBox.SetActive(false);
dialogueActive = false;
currentLine = 0;
}
dText.text = dialogLines[currentLine];
}
public void ShowBox(string dialogue)
{
dialogueActive = true;
dBox.SetActive(true);
dText.text = dialogue;
}
public void ShowDialogue()
{
dialogueActive = true;
dBox.SetActive(true);
}
}