Can anyone help with this, I seem to be stuck? I’m instantiating a prefab (an Asset Bundle to be precise) and want to access an element in that prefab by name. The main asset is an empty and children to it are a number of GUI texts. I’m using the attached script to instantiate the Asset Bundle and to test access to the children. The problem is that I want to access each of the GUI Texts individually by their name. How do I do that?
var assetBundle : AssetBundle;
var instanced : GameObject;
var tests;
function Start () {
if (AssetManager.overlayAsset != null) {
assetBundle = AssetManager.overlayAsset.assetBundle;
var go : Object = assetBundle.mainAsset;
instanced = Instantiate(go);
}
else {
print ("No overlay selected!");
}
print (go.name + " : " + instanced.name);
tests = instanced.GetComponentsInChildren (GUIText);
}
function Update () {
// This toggles all the GUI Texts on and off:
if (Input.GetKey ("up")) {
for (var text : GUIText in tests) {
text.enabled = false;
}
}
else {
for (var text : GUIText in tests) {
text.enabled = true;
}
}
// This changes the first GUI Text:
if (Input.GetKey ("left")) {
var test : GUIText = instanced.GetComponentInChildren (GUIText);
test.text = "WORKS!";
}
}