- Home /
Custom score texture
I was just wondering if anyone has used a texture to display the score. What I want is to design my own numbers 0 - 9 and use this texture as the font display instead of a GUI font. Has anyone used this technique before. It's just a rough idea I was just wondering if there were any examples out there?
Thanks
I am a programmer and I am pretty much clueless about this kind of stuff, but can you not just use another font ins$$anonymous$$d of the existing one? I do know ttf and higher using B_curves makes them just as pretty when zoomed in or out and a.f.a.i.k. that does not work for textures
Just do it with a ttf, doing it your way is more complicated than it should/has to be, and it would look uneven and sloppy... Why try to do something pretty much pointless when you can do something that people have documented, and the results would look better... Just my opinion though...
Answer by denewbie · Dec 08, 2010 at 01:25 PM
To design textures fonts:
Design 0 - 9 like you mentioned
An array of Texture2D and them in, index 0 for 0 and so on till 9
For the score you're setting, store it as a numeral as per normal
When you want to display the score, convert it to string and parse each character as an integer and use the parsed integers as indexes for your textures.
public Texture2D[] myArray; // slot in your textures on the editor.
int myScore = 10000; // Put any number int textureDimension = 50;
void OnGUI(){
string myStringScore = myScore.ToString();
for (int i =0 ; i < myStringScore.Length ; i++) GUI.drawTexture(new Rect(i * textureDimension , 0, textureDimension ,textureDimension ) , myArray[int.Parse(myStringScore[i] ) ] );
}
Something went wrong with the html formatting. I set the code properly but it just didnt turn out right...
I havent tested the code out cause I dont have unity with me but I hope you can get the idea.
Hey denewbie, thanks heaps for this. $$anonymous$$akes perfect sense! I haven't tested it yet but it looks like it will work. I'll let you know how it goes. Thanks again
No prob. This is definately a workable solution. If there's any trouble its probably just a few $$anonymous$$or bugs. If there's any trouble just come back to me.
Answer by jeriitan · Jan 26, 2012 at 04:39 AM
Can you convert that to JS?
If you want a conversion done for you, post a different question ins$$anonymous$$d of cluttering this one.