Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by darkcookie · Feb 02, 2014 at 08:20 AM · texturetimerfontcounter

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);
     }
     
 }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Benproductions1 · Feb 02, 2014 at 09:38 AM 1
Share

Don't try to reinvent fonts, just use 2d text.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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/

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image frogsbo · Feb 02, 2014 at 09:59 AM 0
Share

https://www.google.fr/search?q=unity3d+counter&espv=210&es_sm=93&source=lnms&sa=X&ei=1xbuUov8LqiT0QWQy4DoBA&ved=0CAYQ_AUoAA&biw=1000&bih=650&dpr=1.75

avatar image darkcookie · Feb 02, 2014 at 09:42 PM 0
Share

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.

avatar image Benproductions1 · Feb 04, 2014 at 09:03 AM 0
Share

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.

avatar image darkcookie · Feb 04, 2014 at 09:11 AM 0
Share

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

avatar image Benproductions1 · Feb 04, 2014 at 09:18 AM 0
Share

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.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges