Still a beginner and been trying to change and adapt the tutorials to a small project. I have not been able to get my button to display the correct text. I was trying to use something similar to what Rick did in Glitch Garden’s star power display text. I’ve tried the script on both the button object and the TMP object in the Hierarchy. I have also tried substituting in “Text” for “TMP_Text”, and tried using a regular button instead of a TMP button.
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class RobotCountDisplay : MonoBehaviour
{
[SerializeField] int robots = 10;
TMP_Text robotText;
void Start()
{
robotText = GetComponentInChildren<TMP_Text>();
UpdateDisplay();
}
private void UpdateDisplay()
{
robotText.text = robots.ToString();
}
}
Thanks!