I am trying to populate a menu of profiles, my template has an Image and a Text (TMP) as a child object on it.
so I am collecting all of the templates using the findGameObject with tag and then using a foreach loop assigning the text value with a value that I get from a Json file but I cannot seem to change the value of the text on the Text (TMP) in the script.
I have managed to do this with the normal text before the unity update but now it doesn't let me change the text component of the Text (TMP)
This is my Class that I use to read the Json (which works) and try and populate the text
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class JSONReader : MonoBehaviour
{
public TextAsset textJSON;
public PlayerList myPlayerList = new PlayerList();
public GameObject playerTemplate;
public readonly string playerTemplateTag = "playerTemplate";
//Player Model
[System.Serializable]
public class Player
{
public int id;
public string name;
public string imageLink;
}
//Array of Influencers
[System.Serializable]
public class PlayerList
{
public Player[] player;
}
// Start is called before the first frame update
void Start()
{
myPlayerList = JsonUtility.FromJson<PlayerList>(textJSON.text);
PopulatePlayerSelect();
}
private void PopulatePlayerSelect()
{
var buttonGameObjects = GameObject.FindGameObjectsWithTag(playerTemplateTag);
foreach(GameObject playerTemplate in buttonGameObjects)
{
var image = playerTemplate.GetComponentsInChildren<Image>();
var name = playerTemplate.GetComponentsInChildren<TextMeshProUGUI>();
Debug.Log(name);
}
}
}
I can access the text objects within the foreach loop but I cant seem to change the text value.
am I doing something wrong?