i have run this code and it is working fine with numbers. is there an easy way i can add a big list of names to get randomly picked. thanks alot
using UnityEngine;
using System.Collection;
using UnityEngine.UI;
public class RandomGenerator: MonoBehaviour{
public GameObject TextBox;
public int TheNumber;
public void RandomGenerate() {
TheNumber= Random.Range (1, 10000);
TextBox.GetComponent ().text= TheNumber;
}
}
You can create an array of strings
public string[ ] names;
Then fill the array in the inspector with all the names you want to choose from
Then you can use this function to pick a random from the array
void RandomString() {
int n = Random.Range(0, names.Length);
TextBox.GetComponent<Text>().text = names[n];
}
TheGameNewBie:
You can create an array of strings
public string[ ] names;
Then fill the array in the inspector with all the names you want to choose from
Then you can use this function to pick a random from the array
void RandomString() {
int n = Random.Range(0, names.Length);
TextBox.GetComponent<Text>().text = names[n];
}
Thanks for your reply I’m still a little confused. where do i create the array? and what is the inspector
system
February 7, 2020, 7:43am
4
Do you know how to use the scripting API directly from your script in Visual Studio?
https://docs.unity3d.com/2019.3/Documentation/ScriptReference/Array.html
No i dont sorry, i am new to all this
system
February 7, 2020, 8:24am
6
Did you do the Roll A Ball tutorial? It would give you the basics about how to use Unity and the scripting API. It doesn’t need to download assets, although there is an Asset package. You don’t need it, just follow the tutorial there: https://learn.unity.com/project/roll-a-ball-tutorial
At some point, the instructor ( @Adam-Buckner_1 ) mentions using Ctrl+’ or Cmd+’ to open the scripting API from Unity, these controls do not work with Visual Studio. The controls in Visual Studio are Ctrl+Alt+M and then Ctrl+H.
ok thank you alot for your time and help i will be sure to look into it thanks
i truly thankyou all for taking time to help me. this community is awesome