I want to make an splash text something like minecraft has, but i dont know how to randomly pick text for it. I’ve made string array variable (public string[ ] arrayText) and ive written all the text, im not that professional at unity and scripting so can somebody help me? Also do i need to have text written in code or in inspector? i use unity 3D and Visual Studio 2019 community. thanks:)
BY THE WAY heres the code that i have if someone needs it
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SplashText : MonoBehaviour
{
public string[] splashText;
void Start()
{
}
}
You would need to take a random index to look into the array.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SplashText : MonoBehaviour
{
public string[] splashText;
void Start ()
{
Debug.Log(GetRandomSplashText());
}
string GetRandomSplashText ()
{
// Gets a random number between 0 and the number of strings in the array
int random = Random.Range(0, splashText.Length);
// Returns the index random from the string array
return splashText[random];
}
}
Thank you so much! I’m sorry I posted this 2 times as I needed to make this quick!