H
H
Hrumzik2019-03-09 10:43:55
C++ / C#
Hrumzik, 2019-03-09 10:43:55

How to make text shortening in Unity via C#?

I know it sounds stupid, but I can't really do what I want. In general, I need that when, for example, 1000 points are scored, they themselves are converted to 1k and so on with other numbers, I think you understand. I did it like this:

int k = 1000;
if (score >= 1000) {
//Тут я минусовал кол-во очков и в конце кол-ва прибавлял k
}

I know that this is wrong, but I don’t know how to solve it, because int has a limit, and I peeped from other developers that they “increased the chapel” in the way that I now want to use, so to speak.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Pogrebnyak, 2019-03-09
@Hrumzik

You have a variable responsible for the points and there is a line (for example in the Text component) that will have a different value. Something along the lines of:

if (score >= 1000 && score < 1000000)
   scoreText.Text = (score / 1000f).ToString() + "k";
else if (score >= 1000000 && score < 1000000000) 
   scoreText.Text = (score / 1000000f).ToString() + "m";
else scoreText.Text = score.ToString();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question