How do I add 10 UI text elements to an array or a list...?
Hello everybody. I have 10 UI Text elements which I want to store in either an array or a list but I have been working with this and searching information for the past two days and it's driving me crazy... Please help.
So far I've tried so many different methods. Here are some them:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class InGameSetup : MonoBehaviour {
public GameObject[] letterArr;
void Start () {
letterArr = GameObject.FindGameObjectsWithTag ("Letter");
print (letterArr.Length);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class InGameSetup : MonoBehaviour {
public List<GameObject> letterList;
void Start () {
letterList = GameObject.FindGameObjectsWithTag ("Letter");
print (letterList.Count);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class InGameSetup : MonoBehaviour {
public List<GameObject> letterList;
void Start () {
foreach (GameObject obj in GameObject.FindGameObjectsWithTag("Plane"))
{
letterList.Add (obj.gameObject);
}
}
}
When i print out the length of the array or list I either recieve 0 or nothing...
10text.jpg
(49.3 kB)
Comment
Answer by SKJuhl · Aug 28, 2017 at 05:45 PM
UPDATE: I found this out by myself.
Apparently this won't work if the UI Text elements are not active...:
smh.jpg
(48.0 kB)
This was the code I used if you're interested:
foreach(GameObject obj in GameObject.FindGameObjectsWithTag("Letter")) {
letterList.Add (obj.gameObject);
print (letterList.Count);
}