How to find a GameObject variable within the script using a string?

So pretty much I have a string value and I want to return the GameObject variable that I made within a script (not the scene)

So:

Something along those lines. So I created a string value of the name of the GameObject and I want to use that string to return the variable GameObject so I can instantiate it. Any ideas? Thanks

With GameObject.Find(instantiate) ? You are not very clear in your question… however you can also load assets dynamically with AssetBundle if it’s not in the current scene (it requires Pro license I think).

If you just want to get a random prefab from a list I would suggest to declare an array of prefabs in your script and use a Random.Range to get one element.

Instead of doing that, just use an array instead.

var randomInt : int = 1;
var prefabs : GameObject[];

function GenerateLevel() {
	Instantiate (prefabs[randomInt]);
}

–Eric

@Eric,

That’s actually a lot easier! Thanks for helping me out. I really appreciate it!

Regards,
Frank