Hello,
I have a canvas as an UI-Element to display properties of a game-element.
For every property I want to create manual a Text (I use Text Mesh Pro).
If a Gameobject creates now a copy of this UI-prefab, I want to “fill” the text with the properties of the Gameobject.
I got the properties. But I can’t “adress” the Text in a right way:
I have my canvas, which got this script:
public class Canvas_TankControl : MonoBehaviour
{
Tank tank;
public TextMeshPro tmp_tankName;
public void init(Tank _tank)
{
Debug.Log(_tank.name); // this gets the name correct!
tank = _tank;
TextMeshPro[] tmps;
tmps = this.GetComponents<TextMeshPro>(); // I hoped to get on this way all TextMeshPro-Texts
Debug.Log("tmps.Length: " + tmps.Length); // this results in zero "catches"
foreach(TextMeshPro tmp in tmps)
{
if(tmp.name == "tmp_tankName") // if the name of the TextMeshPro is "xy" fill it with the correspondent property
tmp.text = tank.name;
}
}
This is the prefab:
I hope, someone can help me. The components are still a riddle wrapped up in an enigma for me