- Home /
 
instantiate an prefab and get its child's script
I have a gameobject with 2 child and i instantiate it in script.
and i would like to call the public function in the healthbar's script A, but i fail.
the hierachy is as below playercard -->healthbar //script A attached -->playericon
and the code of instantiate is:
 GameObject loadedPrefab = Resources.Load("NGUI/Membercard") as GameObject;
 NGUITools.AddChild(this.gameObject,loadedPrefab);
 loadedPrefab.transform.GetComponentInChildren<teammatehpbar>().setvaraible(playerid,playernickname,maxhealth,currenthealth,maxmagic,currentmagic);
  
 
               as i have some other playercard in the game, so i would like to avoid using gaemobject.find, how can i solve my problem? Thank you
Answer by Unity_gamer · Feb 17, 2014 at 10:07 AM
Hey,
Try this and post the result
 GameObject loadedPrefab = Resources.Load("NGUI/Membercard") as GameObject;
 loadedPrefab.transorm.FindChild("YOUR CHILD GAME OBJECT NAME").GetComponent<teammatehpbar>().setvaraible(playerid,playernickname,maxhealth,currenthealth,maxmagic,currentmagic);
 
              Your answer
 
             Follow this Question
Related Questions
transform.root and empty root game objects don't play nice 1 Answer
Text Not Being Displayed above Instantiated Prefabs 0 Answers
GetCompontentInChildren erratic behaviour 0 Answers
how do I change the properties of a material that are on the children of an object on script? 1 Answer
Get sphere at run time 1 Answer