How do i turn this float score text into real UI text ?
Every time this bool
is false
i want to increment a score
field value
Here is the code
public float score;
void Update ()
{
if (playerControllerScript.isOnGround == false)
{
score++;
}
}
Hi,
You have to get a reference somewhere to a real UI text. (could be Text from Canvas, or 3D Text)
Once you get that reference, you just have to set the text string to the score : something like
myScoreText.text = score.ToString();
You could use the function String.format to control the format of your float displayed.
In your case, I suggest you to use an event (could be a Unity event or an Action), to raise when you’re changing the boolean isOnGround, inside the player Controller script.
That way, in your script, you could listen to this event and update your score & your UI text at the same time, without having to wait for it inside an Update function. (which is not a good thing to do if you have hundreds/thousands of objects)