Error: ArgumentOutOfRangeExeption: Argument is out of range. Parameter name: index
I'm following a series of youtube tutorials and I reach the stage where I hit this error. (I have tried contacting the video maker but havent yet got a reply.
My error is ArgumentOutOfRangeExeption: Argument is out of range. Parameter name: index
I will copy in my script below, any help is appreciated
using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI;
public class DialogueSystem : MonoBehaviour { public static DialogueSystem Instance { get; set; } public GameObject dialoguePanel; public string npcName; public List dialogueLines = new List();
Button continueButton; Text dialogueText, nameText; int dialogueIndex;
// Use this for initialization void Awake () { continueButton = dialoguePanel.transform.FindChild("Continue").GetComponent(); dialogueText = dialoguePanel.transform.FindChild("Text").GetComponent(); nameText = dialoguePanel.transform.FindChild("Name").GetChild(0).GetComponent(); continueButton.onClick.AddListener(delegate {ContinueDialogue();});
dialoguePanel.SetActive(false);
if (Instance != null && Instance != this) { Destroy(gameObject); } else { Instance = this; } }
public void AddNewDialogue(string[] lines, string npcName) { dialogueIndex = 0; dialogueLines = new List(lines.Length); dialogueLines.AddRange(lines);
this.npcName = npcName;
Debug.Log(dialogueLines.Count); CreateDialogue(); } public void CreateDialogue() { dialogueText.text = dialogueLines[dialogueIndex]; nameText.text = npcName; dialoguePanel.SetActive(true); } public void ContinueDialogue() { if (dialogueIndex < dialogueLines.Count-1) { dialogueIndex++; dialogueText.text = dialogueLines[dialogueIndex]; } else { dialoguePanel.SetActive(false); } }
}
Your answer
