- Home /
transform.Find() returns a Transform?
I am trying to write a code to make a GameObject turn its children and its children's children MeshRenderer on. I want to turn a single child and its children on at 60 seconds intervals. I wrote this and the console returned UnityEngine.Transform cannot be converted to UnityEngine.GameObject. This is not the whole function, but the problem lies in var D : GameObject = transform.Find("D"); if there are any other problems with my code please tell me. The script is on an empty GameObject that has children with children.
function Death () { on = true; var D : GameObject = transform.Find("D"); var Dfire : GameObject = D.transform.Find("Flame"); D.renderer.enabled = true; var dfs : Renderer[]; dfs = Dfire.GetComponentsInChildren(Renderer); for (df in dfs) df.enabled = true; yield new WaitForSeconds(60); if (on) { var E : GameObject = transform.Find("E"); var Efire : GameObject = E.transform.Find("Flame"); E.renderer.enabled = true; var efs : Renderer[]; efs = Efire.GetComponentsInChildren(Renderer); for (ef in efs) ef.enabled = true; } else return; yield new WaitForSeconds(60);
if (on) {
var A : GameObject = transform.Find("A");
var Afire : GameObject = A.transform.Find("Flame");
A.renderer.enabled = true;
var afs : Renderer[];
afs = Afire.GetComponentsInChildren(Renderer);
for (af in afs)
af.enabled = true;
}
else return;
yield new WaitForSeconds(60);
Answer by Lovrenc · Dec 30, 2012 at 12:43 AM
Yep it does and it should. What you need is
GameObject.Find("A");
or if you must
transform.Find("A").gameObject;
Your answer
Follow this Question
Related Questions
Finding Children question 3 Answers
Finding object with transform 1 Answer
Find Transform in the scene 2 Answers