- Home /
Question by
Kachimov · May 23, 2020 at 07:57 PM ·
scripting problemscript.referenceinstantiate prefab
Reference to component of instantiated prefab from another script
I'm instantiate prefab in script A, how can i reference to it components from Script B? See pics below: So, I need a reference to playerScriptComponent
screenshot-20.jpg
(59.6 kB)
screenshot-21.jpg
(88.6 kB)
Comment
Answer by Kachimov · May 23, 2020 at 08:18 PM
private GameObject battleSystemScript;
private Unit playerScriptComp;
battleSystemScript = GameObject.Find("Player1(Clone)");
playerScriptComp = battleSystemScript.GetComponent<BattleSystem>().playerPrefab.GetComponent<Unit>();