• 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 11:25 PM · fontcustomcounterclocktexure

Clock, numbers past 2 digits????

My problem is that i cant seem to get my timer/clock/counter to get past the 2 digits... OK so example once you input a number for example 9 you only use 1 digit , after 9 comes 10 (2 digits 1 and 0 ).....I can get up to two digits, but i don't know how to get to numbers with 3 digits or more ...like 100...

 #pragma strict
 var TotalPoints : int; 
 var CoinsTextTexture: Texture;
 
 var fontSize  : int = 20;
 
 
 var numbers : Texture2D[];
 var digit1 : int;
 var digit2 : int;
 var digit3 : int;
 
  
 function Update(){
 digit1 = TotalPoints%10;//flips after 10
 digit2 = Mathf.Floor(TotalPoints*.1);//changes every 10
 digit3 = // how do i do this one???!!!!! and make digit2 flip back to 0 after reached 10
 }
 
 function OnGUI(){
 
     GUI.DrawTexture(Rect(Screen.width*0.7,Screen.height*0.01,190,100), CoinsTextTexture);
      
      GUI.DrawTexture(Rect(Screen.width*0.9,Screen.height*0.01,100,100), numbers[digit1]);
     if(digit2>=1){
      GUI.DrawTexture(Rect(Screen.width*0.85,Screen.height*0.01,100,100), numbers[digit2]);
      }    
 }
Comment
Add comment
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

2 Replies

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

Answer by JCX · Feb 02, 2014 at 11:58 PM

 if(digit2>10)
 {
     digit2-=10;
     digit3++;
 }

or

 digit3 = Mathf.Floor(TotalPoints*.01);

or you can convert it to string and each letter convert back to int

 string s = TotalPoints.toString()
 digit1 = (int)s[2];
 digit2 = (int)s[1];
 digit3 = (int)s[0];
Comment
Add comment · Show 7 · 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 darkcookie · Feb 03, 2014 at 12:01 AM 0
Share

how can i convert it to string and back? can you show me an example please? by the way thank you for the reply

avatar image JCX · Feb 03, 2014 at 12:16 AM 0
Share

i don't know how in unity script but looks like it's same string as in c# http://docs.unity3d.com/Documentation/ScriptReference/String.html http://msdn.microsoft.com/en-us/library/system.string(v=vs.110).aspx

avatar image darkcookie · Feb 03, 2014 at 12:24 AM 0
Share

i get errors when i try this .. aside from the missing ; after toString()....i get missing semicolon errors on:..... how come?

 digit1 = (int)s[2];
 digit2 = (int)s[1];
 digit3 = (int)s[0];
avatar image darkcookie · Feb 03, 2014 at 12:36 AM 0
Share

Prbabably I have to convert it to java script ....but im not sure how to .. I dont understand what (int)s[0]; is doing

avatar image JCX · Feb 03, 2014 at 12:48 AM 0
Share

this works:

     var TotalPoints:int = 123;
     
     var s:String = TotalPoints.ToString();
     
     Debug.Log(s);
     
     var digit1:int = int.Parse(""+s[0]);
     var digit2:int = int.Parse(""+s[1]);
     var digit3:int = int.Parse(""+s[2]);
     
     Debug.Log(digit1);
     Debug.Log(digit2);
     Debug.Log(digit3);

dunno better way then adding char to strign right now, i use c# not unityscript

Show more comments
avatar image
0

Answer by GTX Titan · Feb 03, 2014 at 12:48 AM

Okay time for magic:

 digit3 = Math.Floor(TotalPoints/100); 
 digit2 = Math.Floor((TotalPoints-digit3*100)/10);
 digit1 = Math.Floor((TotalPoints-digit3*100)-digit2*10);
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 darkcookie · Feb 03, 2014 at 01:20 AM 0
Share

sorry but this gives a negative number if its on the first digit

avatar image GTX Titan · Feb 03, 2014 at 01:38 AM 0
Share

It can't give negative... if there is no digit3 digit3 = 0 and when you do 0*100 and subtract with it...

avatar image GTX Titan · Feb 03, 2014 at 01:40 AM 0
Share

Believe me this is as simple as it gets and it works i tested.

avatar image GTX Titan · Feb 03, 2014 at 01:41 AM 0
Share

For number 9 it gets these: digit3 = 0 digit2 = 0 digit1 = 9 For number 21 it gets these: digit 3 = 0 digit2 = 2 digit1 = 1

avatar image GTX Titan · Feb 03, 2014 at 01:43 AM 0
Share

I have "extended" mathemathics in high school and i'm getting straight A's with no effort whatsoever :)

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

19 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

Related Questions

How can I use a font without GUI? 1 Answer

How to find a font via script? 2 Answers

Custom Font not loaded in Android 0 Answers

Need help with SaveFontTexture fonts 1 Answer

Custom score texture 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