- Home /
Multiple technical issues/too broad
Using images to show numbers
I have images of 0 to 9 numbers. I want to use them to show numbers like score and health, etc. The system will calculate the score and health and then show. To show it as image, I think the system needs to find out the number of each unit of a number. Then combine the numbers to form score or health. But how can I do that by C# script?
This question is too broad, involving multiple technical issues...and boarders on asking someone to write a script for you. Unity Answers focuses on answering questions about single, specific technical issues to help you write your own code. The starting point for your problem is to figure out how to change a game object's visible texture. There are multiple approaches...some more efficient than others...some more complex than others.
As you break your problem down to specific issues, we welcome your single specific technical questions.
Answer by KevLoughrey · Apr 24, 2014 at 03:03 PM
It'd probably be easiest to make your images 1 - 9 into a font and draw that to the GUI.
Otherwise, you'd need to do something like breaking the score (for example, an int
) into its component digits by converting it to a string, then to a charArray, then map each element of that array to the corresponding number image.
If I want to use the second one, what method can I use to break the score?
Off the top of my head, to convert the string to an array of characters you'll need something like: int.ToString().ToCharArray()
Then you can access each element of the array and map it to an image. For example, if you name your images like "0.png", "1.png", etc. You can call them using something like:
for (int i = 0; i < array.Count() - 1; i++) {
//Pseudocode - can't remember the exact draw syntax
GUI.Draw(array[0] + ".png");
}
Obviously that code's not going to work. Can't remember any of the syntax off the top of my head, but it's the right idea. I'd still recommend making a custom font though! There are plenty of free font generators online.
Follow this Question
Related Questions
Creating a Lifebar with simple GUI in C# 3 Answers
Healthy Floating Numbers 3 Answers
Health to come above enemy when clicked 1 Answer
How to add score/health ? 2 Answers
Score that ticks up 1 Answer