- Home /
Question by
Ryuzaki92 · Apr 28, 2017 at 05:46 AM ·
error messagereferenceexceptionmissingmissingreferenceexception
Unassigned Reference Exception ?
Hello, I have strange problem with my code and I'm not sure how to tackle that. So I have :
-Generator object with script below as prefab. -Solar Panel object with button, text and image components (4 children) also prefabed -I have added Solar Panel to the Generator object in inspector as a prefab -I have added Generator to Solar Panel Button and BuySolarPanel() method as OnClick() event also as a prefab;
I want this button to instatiate (which it does) and then after clicking it change one if it's text components, but I got missing reference error. I'm sure everything is connected in Inspector and it points me to the last line of code myText = solarPanel.GetComponentsInChildren<Text>();
Here's the code :
public GameObject[] buildObjectsArray;
public GameObject parentObject;
private GameObject solarPanel;
private int energy;
private int objectCounter = 0;
private void Start()
{
solarPanel = buildObjectsArray[0];
}
private void Update()
{
if (energy == 100 && objectCounter == 0)
{
Instantiate(solarPanel, parentObject.transform);
objectCounter++;
Debug.Log(objectCounter);
}
}
public void BuySolarPanel()
{
Text[] myText;
myText = solarPanel.GetComponentsInChildren<Text>();
}
Comment