I'm now getting a nullReferenceException:
using UnityEngine;
using System.Collections;
public class ObjectArray : MonoBehaviour {
GameObject uiObject;
string[] array1;
Vector3 temp = new Vector3(0,50.0f,0);
void Start() {
array1 = new string[8] {"Do", "Re", "Mi", "Fa", "So", "La", "Ti", "Doe"};
/*for(int i=0; i < array1.Length; i++) {
Debug.Log(array1);
} */
createButtons();
uiObject = GameObject.Find("Button");
}
public void createButtons() {
//Debug.Log("Got here!");
for (int i = 0; i < array1.Length; i++) {
GameObject newButton = GameObject.Instantiate(uiObject) as GameObject;
NGUITools.AddChild(newButton);
UILabel newButtonLabel = newButton.GetComponentInChildren<UILabel>();
newButtonLabel.text = array1;
newButton.transform.position += temp;
} // end for()
} // end createButtons()
} // end class()
I've created a prefab of a button and I need to instantiate it in the scene but think the error might be because I do not know how to find the prefab since GameObject is only finding items in the hierarchy and not the project view itself.