So i cant for the life of me figure out the issue
heres the error im getting
Error in console
NullReferenceException: Object reference not set to an instance of an object
GameController.UpdateInfo () (at Assets/newScripting/GameController.cs:265)
GameController.Update () (at Assets/newScripting/GameController.cs:174)
here is the line of code the error is pertaining to
UpgradeManager.Instance.AddButton ("Upgrade Keyboard\n$" + keyboardCost, keyboardCost, "proKeyboard");
and here is the function thats being called
function being called
public void AddButton(string text,int cost,string type){
Button[] buttons = this.GetComponentsInChildren<Button> (true);
foreach (Button but in buttons) {
if (but.GetComponent<ButtonInfo> ().buttonType == type) {
return;
}
}
GameObject b = Instantiate (buttonPrefab, new Vector3 (20, -bc * 50, 0), buttonPrefab.transform.rotation) as GameObject;
b.transform.SetParent (transform, false);
b.GetComponentInChildren<Text> ().text = text;
b.GetComponent<Button> ().onClick.AddListener (delegate {
HandleButton(type);
});
b.GetComponent<Button> ().onClick.AddListener (delegate {
this.buttonPressed(b.GetComponent<Button>());
});
b.GetComponent<ButtonInfo> ().buttonCost = cost;
b.GetComponent<ButtonInfo> ().buttonType = type;
bc++;
if (bc * 50 > 250) {
GetComponent<RectTransform> ().sizeDelta = new Vector2 (237, bc * 50);
} else {
GetComponent<RectTransform> ().sizeDelta = new Vector2 (237, 250);
}
}
im not sure what the issue is i have the “buttonPrefab” as a public gameobject and i set it in the inspector