Array Index Is Out Of Range...
Please, thank you, could you say what's wrong with this code:
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class Ourscrp : MonoBehaviour {
/* // Use this for initialization void Start () {
}
// Update is called once per frame
void Update () {
}*/
public QuestionList[] questions;
public Text QText;
public void OnClickPlay()
{
QText.text = questions[Random.Range(0, questions.Length)].question;
}
} [System.Serializable] public class QuestionList { public string question; public string[] answers = new string[3]; } it is a button and text field to show questions in. Like a quiz game.
Comment
Answer by TheyLeftMe4Dead · Jan 16, 2017 at 03:48 AM
Try subtracting 1 from questions.Length.
Other than that, here are some ideas:
A. Is questions[ ] null?
B. What happens if questions[ ].length is 1?
C. Does Random.Range(0, questions.Length) return an integer?
D. Does Random.Range include or exclude the last element?