C# Random String Array help

void OnGUI(){
string splashes = {“Less than one sold!”, “lol”,“lmao”,“what?”};
System.Random random = new System.Random();
string quote = splashes[random(splashes)];
GUI.Label(new Rect(50,500,300,100),quote);
}

//I’m trying to create a GUI which will have random sentences in the splashes string. I have no idea how to do this, but can someone please find a way on how to do this? So for example, when I start up the game, it will state “Less than one sold!”, “lol”, “lmao”, or “what?”. If you have every played Minecraft where there are those hundreds of different yellow sentence splashes at an angle, then you should know I want.

You almost had it. See here: Random.Next Method (System) | Microsoft Learn

That method returns an integer from 0 up to but not including maxValue, perfect for use as an index for an array of size maxValue. Your modified code would be:

string quote = splashes[random.Next(splashes.Length)];

I should note that I didn’t run this code; I’ll gladly correct it if necessary.

To make things easier, use Random.Range (look it up in the Unity docs), and you should only do it once, in Start or whatever, not every frame in OnGUI, otherwise it will constantly flicker between random strings.