- Home /
The question is answered, right answer was accepted
Find Define GameObject Problem.
Ok another noob problem, hopefully.
I need to define a GameObject by finding it in another object. However it says I can't, not Implicitly something error.
Code:
public GameObject turret;
private GameObject turCamera;
void Start(){
turCamera = turret.transform.Find("turretCamera");
}
What I do wrong?
Answer by Jake-L · Sep 04, 2013 at 07:54 AM
Transform.Find() returns a Transfom and you can't implicitly convert a Transform to a GameObject.
Try this:
void Start() {
Transform tf=turrent.transform.Find("turrentCamera");
if (tf)
turCamera=tf.gameObject;
}
Ok this works thanks... $$anonymous$$an I hate it when something so small just stops everything.
Thanks again.
Answer by Rebnerod · Sep 04, 2013 at 08:01 AM
Probabbly you can do it like
turCamera = gameObject.FindWithTag("example").transform;
or
turCamera = gameObject.Find("turretCamera").transform;
Sorry, didn't see your answer was awaiting approval when I wrote $$anonymous$$e. However, it's a good practise to check for null before accessing the transform.
How come gameObject. does not show Find for me?
Busy trying Jakes answer...
Yes you're right. I also think that your answer is a better option