Arrays Question

Hey, ive made an array for a dialogue system where its serialisable so i can write the text out in the inspector.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using TMPro;

[System.Serializable]
public class RdmDialogue : MonoBehaviour
{

    public TextMeshProUGUI TextBox;
    [TextArea(3, 10)]
    public string[] Opt1 = new string[4];
    public string[] Opt2 = new string[4];
    public string[] Opt3 = new string[4];
    public string[] Opt4 = new string[4];
   

    public void Random()
    {
        int randomNum = Random.Range(1, 4);

        if (randomNum == 1)
        {
            TextBox.text = Opt1[0]
        }
  if (randomNum == 2)
        {

            TextBox.text = Opt2[0]
        }
    }
//etc
}

when you press the button it runs Random() and will make the text for the first element of the array appear but i was wondering how i would code a next sentence button that would change the [0] int to +1 so that it types out the next element

@DotArt One way would be to move randomNum to a module scoped variable.

int randomNum = 0;

public void NextSentence()
{
    if (randomNum == 1)
    {
       TextBox.text = Opt1[1];
    }

   //etc, but look into Switch statements

}

A basic programming trick with arrays is that the index (the 3 in Opt[3]) can be a variable. Instead of saying “if I roll a 1, I want to use item 1, if I roll a 2…” you can say “use the number I rolled”. For example:

int randomIndex=Random.Range(0,4); // rolls 0-3
  TextBox.text = Opt[randomIndex];
  // an array with 4 things has indexes 0,1,2 and 3