i want a random name selector for the npc where i can have a bunch of names in a list and it randomly picks a name from there and put it as that npc name and can reference that npc from a thread to use in dialogue and and i want it where it cant do this for more then one npc.
ps i have dislexsya sorry for that
using UnityEngine;
using System.Collections;
public class RandomNameTest : MonoBehaviour {
private string[] names = new string[] { "Peter", "Ron", "Satchmo" };
public string GetRandomName()
{
return names[Random.Range(0, names.Length)];
}
void Start()
{
Debug.Log(GetRandomName() + " asks you nicely to use the learning modules");
}
}
http://unity3d.com/learn/tutorials/modules
The unity engine (and C#) have a random function that will grab a random number within a certain range. Here is a quick example for one character. TODO: Make a Names class to store all the names only once, and add a function which will return a name.
void Start()
{
System.Random rand = new System.Random();
int number = rand.Next(0, 500)
List<string> names = new List<string>();
for(int i = 0; i < 500; i++)
{
names.Add(A name that you grab somehow)
}
//now get a random name by using this
string myName = names[number];
}
You could use the random number generator, then make a switch statement.