- Home /
Store Child Object in Var
Hey all,
I am trying to use this code to store a child object in a variable.
cannon1 = gameObject.transform.FindChild("TurretCannon").GameObject;
But it's not working? Can someone tell me what I am doing wrong?
Thanks Steve
Answer by roojerry · Mar 20, 2013 at 04:34 PM
the first problem I see is that .GameObject;
should be .gameObject;
Yap that's only issue, but it's also give error on editor when you comple your script.
I am not getting error, I said the code written by $$anonymous$$r. Steve is also give error at time of compiling if script assigned to any Gameobject. because transform doesn't have any property which denotes GameObject word, its have a .gameObject which return Object which are using the transform
Just noticed you aren't the question asker, sorry. Thought there was still an problem, but this change should have fixed that compilation error
Hey All, I tried using a lower case g but ins$$anonymous$$d I get this error at run time.
NullReferenceException PlayerObjectHealth.Start () (at Assets/Scripts/PlayerObjectScripts/PlayerObjectHealth.js:29)
Your answer
Follow this Question
Related Questions
How to access objects attached to other objects 1 Answer
Make gameobject a child without affecting scale? 1 Answer
Having Parent Origin Follow Child Objects 1 Answer
Can't Return the Tag of a Child Object 4 Answers
Instantiate and Scaling 0 Answers