#i need help

1 messages · Page 1 of 1 (latest)

spice plover
#

using UnityEngine;
using UnityEngine.UI;
public class score : MonoBehaviour{

public Transform player;
public Text TMPro;

// Start is called before the first frame update
void Start()
{
    
}

// Update is called once per frame
void Update()
{
    TMP_Text.text = player.position.z.ToString();

}

}
can someone tell me what im doing wrong and what i should do instead

long meadow
#

Why are you using TMPro?

#

Just wondering

spice plover
#

someonje told me

#

i want to use textmeshpro

#

to make a score board

dusty swift
#

Code gets deleted, that's the anti spam bot, it removes unformatted code

long meadow
#

You can just use standard canvas to do this type of stuff

dusty swift
#

Anyway, TextMeshPro is perfectly fine, old Text is legacy, deprecated

long meadow
#

Personally I don't use it, but it sounds like it's confusing them

spice plover
dusty swift
#

You don't, use TextMeshPro

buoyant cobalt
#

I think TMPro text is crispier better looking overall it is worth using

spice plover
dusty swift
#

Keep what you already have, only change the code so it accepts TMP

#

It's a 10-second edit

spice plover
#

but what do i change

#

just these 2

#

public Text TMPro;

buoyant cobalt
#

you need to add the TMPro library

spice plover
#

TMP_Text.text = player.position.z.ToString();

dusty swift
#

First, the using directive at the top

#

using UnityEngine.UI is unnecessary now

spice plover
#

k

#

did that

buoyant cobalt
#

and after that change public Text to public textmeshprougui

#

\

dusty swift
#

By deleting that, you'll get an error

#

Where it says public Text

#

That's what you're going to replace. Text refers to the old text, now deprecated

#

Add a new directive at the top, so it recognizes Text Mesh Pro types: using TMPro;

spice plover
#

k

dusty swift
#

Then, instead of public Text myText;, have public TMP_Text myText;

#

And that's about it, you just have to drag-drop now

spice plover
#

k imma try it rn

#

do i keep this line

#

void Update()
{
TMP_Text.text = player.position.z.ToString();

#

or do i change the first part

dusty swift
#

You change what's before the dot so it's the same as the variable name you just changed

#

Still using my example, that would be myText.text = ...

spice plover
#

ty so much

#

it works

dusty swift
#

Nice! I'll let you archive the threads you created so it doesn't flood the list too much.
There should be an "Archive Thread" option in that menu:

spice plover
#

yeh

dusty swift
#

(I don't have it since I didn't create it)