- Home /
counter but with textures?
My problem is that i cant wrap my head around how make a counter that just counts but with textures. I have textures of numbers 0-9 ...how can i make it count past 9 and so on ....like for example for 10 it would be (one and zero). I put the textures in an array an did this.... how can I get it to count to higher numbers?
#pragma strict
var TotalPoints : int;
var CoinsTextTexture: Texture;
var fontSize : int = 20;
var zero:Texture2D;
var one:Texture2D;
var two :Texture2D;
var three:Texture2D;
var four:Texture2D ;
var five:Texture2D ;
var six:Texture2D ;
var seven:Texture2D ;
var eight:Texture2D ;
var nine:Texture2D ;
function OnGUI(){
GUI.DrawTexture(Rect(Screen.width*0.7,Screen.height*0.01,190,100), CoinsTextTexture);
if(TotalPoints == 0){
GUI.DrawTexture(Rect(Screen.width*0.9,Screen.height*0.01,100,100), zero);
}else if(TotalPoints == 1){
GUI.DrawTexture(Rect(Screen.width*0.9,Screen.height*0.01,100,100), one);
}else if(TotalPoints == 2){
GUI.DrawTexture(Rect(Screen.width*0.9,Screen.height*0.01,100,100), two);
}else if(TotalPoints == 3){
GUI.DrawTexture(Rect(Screen.width*0.9,Screen.height*0.01,100,100), three);
}else if(TotalPoints == 4){
GUI.DrawTexture(Rect(Screen.width*0.9,Screen.height*0.01,100,100), four);
}else if(TotalPoints == 5){
GUI.DrawTexture(Rect(Screen.width*0.9,Screen.height*0.01,100,100), five);
}else if(TotalPoints == 6){
GUI.DrawTexture(Rect(Screen.width*0.9,Screen.height*0.01,100,100), six);
}else if(TotalPoints == 7){
GUI.DrawTexture(Rect(Screen.width*0.9,Screen.height*0.01,100,100), seven);
}else if(TotalPoints == 8){
GUI.DrawTexture(Rect(Screen.width*0.9,Screen.height*0.01,100,100), eight);
}else if(TotalPoints == 9){
GUI.DrawTexture(Rect(Screen.width*0.9,Screen.height*0.01,100,100), nine);
}
else{
GUI.skin.label.fontSize = GUI.skin.box.fontSize = GUI.skin.button.fontSize = fontSize;
GUI.contentColor = Color.black;
GUI.Label (Rect (Screen.width*0.9,Screen.height*0.01, 100, 100), ""+TotalPoints);
}
}
Answer by frogsbo · Feb 02, 2014 at 09:54 AM
use variable like n1,n2,n3, its easer.
user an array like
var numbers : texture2d[];
then use numbers[1] etc to choose your texture
use this maths:
digit1 = Math.Floor(current number*.1);//changes every 10
digit2 = current number%10;//flips after 10
numbers[digit1], numbers[digit2],
otherwise use all numbers on same texture and change offset.
here is a calculator code http://www.pencilsquaregames.com/2013/10/calculator-for-unity3d/
I still don't understand the math part how do i get the digit2 to not get past 9 just like digit1...i made digit3 so once digit2 reaches 10, digit3 becomes 1 and everything else continues to count.
Easiest to understand would be to convert the integer to string and parse each character. Let the language do the work for you, however (and again) use text ins$$anonymous$$d. You're creating so much pain for yourself.
would 3d let me use my textures?how does this work? ohh and yeah by the way i fixed my code already and i did use parse:D
Can you help me with this error i got?(new post) i also posted the fixed code there. http://answers.unity3d.com/questions/631347/deactivate-un-used-zeros.html
The whole point of fonts is so that you don't have to use your own individual textures and the whole font system does everything for you. You can just make your own font if you want your text to look a specific way.
Your answer
Follow this Question
Related Questions
Can anyone help ?? Timer and gui 0 Answers
C# countdown timer 9 Answers
player on fire timer 2 Answers
Timer to call Instantiate 1 Answer
How to add a counter on screen! 2 Answers