Home > database >  How Do you make a public TMPText unity C#
How Do you make a public TMPText unity C#

Time:02-15

I am new to unity and I was wondering if there is any way to call a Public TextMeshPro Because I have been trying to make a score timer Current Script For example I use public Text ScoreText; . So is there any way to work to do something like Public Tmp_Text ScoreText; or something Like That? (Sorry I am pretty new)

CodePudding user response:

I wish you good luck on your journey of learning unity. There are several things you need to keep in mind to solve your problems. Follow tutorials and learn from them. Check unity api to get references on how specific modules/commands function. In your case that would be this reference.

Here's the shortest way to do what you want: add using TMPro;to the very top of your script declare your variable public TextMeshProUGUI scoreText use your variable in code to set text;

void AddPoints(int pointsEarned)
{
   currentScore  = pointsEarned;
   scoreText.SetText(currentScore.ToString());
}
  • Related