what i’m trying to do is instantiate several objects from one string containing many names.
lets say we have
private string nameofobjects;
void Update ()
{
nameofobjects = nameofobjects+"_"+(text you entered);
//Example nameofobjects would be "_car_bus_house"
}
void Start()
{
//Instantiate nameofobjects as gameobjects
}
GaRzY
December 25, 2013, 9:51pm
2
The nameofobjects string contains class names (ex: Car.cs, Bus.cs) or only you want to do this?:
GameObject obj = new GameObject();
obj.name = “car”.
Use String.Split to get an array of object names.
char[] separator = new char[] {'_'};
StringSplitOptions options = StringSplitOptions.RemoveEmptyEntries;
string[] names = nameofobjects.Split(separator, options);
Then you can do something for each string. I don’t know what you want to do, but the most obvious thing that came to mind was loading game objects via Resources.
foreach (string name in names)
Instantiate(Resources.Load(name));