Hi,
I have struggled with this for too long, can someone please help and/or direct me.
Here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class GameController : MonoBehaviour {
public TextMeshProUGUI scoreText;
void Start()
{
scoreText = GetComponent<TextMeshProUGUI>() ?? gameObject.AddComponent<TextMeshProUGUI>();
scoreText.text = "Score: ";
}
}
Here are other details that might be important:
- In my hierarchy I have “Main Camera and directional light” as per new project.
- I have added a canvas (no changes)
- I have added a textmeshpro text UI to the canvas. I have changed the text input box to “I see TEXT”, and yes I do see the text when I press play.
- I have added a empty gameobject.
- I added the above script to the gameobject,
- I have dragged the textmeshpro text to “Score text” on the Gameobject that holds the script.
When I press play I would expect the “I see TEXT” to change to "Score: ". (I have debugged the code and the text does change, it just doesn’t display in game view)
The above doesn’t happen, what rookie mistake am I making?