- Home /
 
 
               Question by 
               lochan_vishwanath · Feb 10, 2019 at 04:01 PM · 
                scripting problemprefabprefabsassignassign-variable  
              
 
              how do I assign a prefab's child to another prefab's script's public variable?
I have attached 2 images, i need to assign GAME OVER PANEL from main prefab to RedPlain's (prefab) dangerobj's(script) public variable called panel. the problem is i am assigning the same every time i make a new scene instead i want to assign it and set it as a default value in prefab editor itself.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Magso · Feb 10, 2019 at 09:09 PM
You would have to do it by script. Only prefabs in the assets can be assigned by default.
 panel = GameObject.Find("Main/Canvas/GAME OVER PANEL").GetComponent<RectTransform>();
 
              I tried similar code before ins$$anonymous$$d of using GetComponment<>() to retrieve the RectTransform , I wasn't. Thank You.
Your answer