-2

I made a coin collecting system that increases the number on a counter when the player comes in contact with the "coin" > sphere. I used Debug.Log to make sure that the counter works. It does. However, When I use TextMeshPro to display that value, it is stuck at zero.

public float moneyStart;
public float unit;
public float moneyNow;
public float displayedMoney;
private TextMeshPro textsss;

void Start()
{
    TextMeshPro textsss = GetComponent<TextMeshPro>();
}

void OnCollisionEnter(Collision C_Info)
{
    if (C_Info.collider.tag == "Currency")
    {
        displayedMoney = moneyNow + unit;
        textsss.text = displayedMoney.ToString("0");
    }
}

Visual for the counter stuck at zero

The script is in the TextMeshPro Element

  • Am I using TextMeshPro correctly?
  • How can I use it better?
  • Are there any errors?
  • How do I fix it?

1 Answers1

0

Don't pass any argument to the .ToString() method

textsss.text = displayedMoney.ToString();

And to answer your questions, you are using TextMeshPro correctly, updating the text every time the field displayedMoney is getting updated

Geeky Quentin
  • 2,469
  • 2
  • 7
  • 28
  • After not passing a argument to the ToString, There are no errors that show on the console but the counter is still stuck at 0. – TheOdinBorson Jul 24 '22 at 08:34
  • @TheOdinBorson, where are you printing the value? I don't find it in your code. It would be beneficial if you could post your whole code – Geeky Quentin Jul 24 '22 at 08:39