- Home /
Assigning the same randomly generated variable to instantiated objects.
At the moment I'm working on naming bots for my FPS. I'm using an GUIText array to store the various names that are randomly selected at instantiation. How would I be able to pass prior information into a newly instantiated bot object, examples of this would be the randomly generated name and a bot's score.
Comment
Best Answer
Answer by spinaljack · Jun 29, 2010 at 10:47 AM
Simple solution is to declare public variables in the bot script and just edit the relevant information when you instantiate the bot.
Do this:
var RNGScore = Random.Range(0,100);
var RNGName = nameList[Random.Range(0,nameList.length)];
var tempGO = Instantiate(botPrefab);
tempGO.GetComponenet(BotScript).score = RNGScore;
tempGO.GetComponenet(BotScript).name = RNGName;