public void fillCard(int index, string desc, string question, posAnswer[] answers, GameObject buttonPrefab, highlightPointer parent) { GameObject objCanvas = cardReference[index].transform.GetChild(1).gameObject; Text[] output = objCanvas.GetComponentsInChildren <Text> (); output[0].text = question; // NOTE: dynamically generate buttons GameObject[] buttons = new GameObject[answers.Length]; for (int i = 0; i < answers.Length; i++) { // nice circle of buttons around the object Vector3 buttonPos = gameObject.transform.position; buttonPos.x -= 0.1f; buttonPos.z += 0f; buttonPos.y += (0.6f * i) - 2f; // actually instantiate the button buttons[i] = Instantiate(buttonPrefab, buttonPos, Quaternion.Euler(0, 90, 0), objCanvas.transform); // x range is from -60 to 60 buttons[i].GetComponentInChildren <Text>().text = answers[i].option; buttons[i].GetComponentInChildren <Text>().fontSize = 24; buttons [i].transform.localScale = Vector3.one * 0.4f; int tempInt = i; buttons [i].GetComponent <Button> ().onClick.AddListener(() => parent.buttonPressed(tempInt)); } }
// Use this for initialization void Start() { jsonLocationSource = FindObjectOfType <DataLoader> (); data = jsonLocationSource.locationData; for (int i = 0; i < data.places.Length; i++) { GameObject mapPoint = Instantiate(mapPointer); highlightPointer mapPHL = mapPoint.GetComponent <highlightPointer> (); mapPHL.pointLoc = data.places[i]; mapPHL.index = i; } }