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 03, 2014 at 07:01 PM · texture2dcounterzeromeaningful

deactivate un-used zeros

I have a script which counts with textures for example 123 would assign the texture 1,2 and 3 to be rendered, but when I only have 1 digit like (5)the others are set to zero making it look like (500)....so how can i disable the zeros until they become meaningful like in numbers (20) or (560)...

      // varibles begin // 
 var TotalPoints:int; // this variable is edited externaly and shows howmany points we have 
 
 //***************************
 var digit1:int;
 var digit2:int; // all these are to store the integers 
 var digit3:int;
 var digit4:int;
 //***************************
 
 var CoinsTextTexture: Texture; // texture section this is for the text "coins"

 var numbers : Texture2D[];// array of  images of numbers 0-9
 
 //***************************
   
        //end of variables//
  
 
 
  function Update(){
     
     var s:String = TotalPoints.ToString();
 
  
      digit1 = int.Parse(""+s[0]);
      digit2 = int.Parse(""+s[1]);
      digit3 = int.Parse(""+s[2]);
      digit4 = int.Parse(""+s[3]);
    }
      
    function OnGUI(){
    
      GUI.DrawTexture(Rect(Screen.width*0.0,Screen.height*0.75,70,50), CoinsTextTexture);
    
      
      GUI.DrawTexture(Rect(Screen.width*0.0,Screen.height*0.85,100,100), numbers[digit1]);
     
     
      GUI.DrawTexture(Rect(Screen.width*0.04,Screen.height*0.85,100,100), numbers[digit2]);
      
           
      
      GUI.DrawTexture(Rect(Screen.width*0.08,Screen.height*0.85,100,100), numbers[digit3]);
      
      
      GUI.DrawTexture(Rect(Screen.width*0.12,Screen.height*0.85,100,100), numbers[digit4]);
   
 }
Comment
Add comment · Show 6
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 04, 2014 at 09:19 AM 0
Share

Please remove massive amounts of whitespace from the question. Theres no need to leave 5 lines between a function call and the closing bracket.

Also if you're already parsing digits, why not just parse the whole number as one thing and have each character as a digit.

avatar image darkcookie · Feb 05, 2014 at 09:16 AM 0
Share

If I was to parse the whole number i would get false numbers because of the zeros ....... i have 4 digits ( 0 0 0 0 ) if i was to parse a six, i would get this ( 6 0 0 0 ).... now that appears to be 6000 but its just 6. I tried to parse from right to left like (0 0 0 6) but its hard because once you begin counting to more digits for example 15 ( 0 0 1 5) the code actually reads ( 0 0 5 1)....if i swap them single digit # would be in the wrong place:(

avatar image Benproductions1 · Feb 06, 2014 at 08:08 AM 0
Share

You're approaching the whole thing from the wrong direction. There is absolutely no need for you to treat every digit separately.

 var number:int;
 var numbers:Texture2D[];
 
 //then
 var str = number.ToString();
 
 for (var character:char in str) {
     var num = parseInt(character);
     Debug.Log(numbers[num])
 }

This is really just a 10-20 liner, not some huge piece of code

avatar image darkcookie · Feb 06, 2014 at 08:27 AM 0
Share

its telling me I cant convert char to string and that primitive char cant be refined..

avatar image darkcookie · Feb 06, 2014 at 08:54 AM 0
Share

its probably telling me that it cant convert it to string because str is a string and then you re- specify that its a string ...

Show more comments

2 Replies

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

Answer by darkcookie · Feb 05, 2014 at 10:34 PM

After a long struggle i finally got it ... This is not the most efficient way but it worked. If any one has any ideas of how i can make it better or if I'm doing this wrong please tell me. here is the code in case someone has this problem! :]

          // varibles begin // 
 var TotalPoints:int; // this variable is edited externaly and shows howmany points we have 
 
 //***************************
 var digit1:int;
 var digit2:int; // all these are to store the intigers 
 var digit3:int;
 var digit4:int;
 //***************************
 
 var s: String; //this holds the current number
 
 //***************************
 var CoinsTextTexture: Texture; // texture section this is for the text "coins"
 var numbers : Texture2D[];// array of  images of numbers 0-9
 
 //****************************
        //end of variables//
  
 
  function Update(){
     s = TotalPoints.ToString();
     var numberInt: int;
     
     numberInt = int.Parse(s);
  
      digit1 = int.Parse(""+s[0]);
      if(numberInt>9){             // I added this condition becuase i got the index is out of range error..
      digit2 = int.Parse(""+s[1]);
      }if(numberInt>99){
      digit3 = int.Parse(""+s[2]);
      }if(numberInt>999){
      digit4 = int.Parse(""+s[3]);
      }
    }
      
    function OnGUI(){
      
      GUI.DrawTexture(Rect(Screen.width*0.0,Screen.height*0.75,70,50), CoinsTextTexture);// random texture display 
    
                                          //Digit 1
     //**************************************************************************************************************** 
      
        if(s.Length==1){ // if s has 1 digit  ************************************
      GUI.DrawTexture(Rect(Screen.width*0.0,Screen.height*0.85,100,100), numbers[digit1]);
       
       }
       
       
       
                                           //Digit 2
    //**************************************************************************************************************** 
      
        if(s.Length==2){ // if s has 2 digits ****************************
      GUI.DrawTexture(Rect(Screen.width*0.0,Screen.height*0.85,100,100), numbers[digit1]);
      GUI.DrawTexture(Rect(Screen.width*0.04,Screen.height*0.85,100,100), numbers[digit2]);
        
        }
        
        
                                           //Digit 3
    //**************************************************************************************************************** 
           
        if(s.Length==3){ // if s has 3 digits ****************************
      GUI.DrawTexture(Rect(Screen.width*0.0,Screen.height*0.85,100,100), numbers[digit1]);
      GUI.DrawTexture(Rect(Screen.width*0.04,Screen.height*0.85,100,100), numbers[digit2]);
      GUI.DrawTexture(Rect(Screen.width*0.08,Screen.height*0.85,100,100), numbers[digit3]);
        
        }
       
                                           //Digit 4 
    //**************************************************************************************************************** 
       
       if(s.Length==4){ // if s has 4 digits ****************************
      GUI.DrawTexture(Rect(Screen.width*0.0,Screen.height*0.85,100,100), numbers[digit1]);
      GUI.DrawTexture(Rect(Screen.width*0.04,Screen.height*0.85,100,100), numbers[digit2]);
      GUI.DrawTexture(Rect(Screen.width*0.08,Screen.height*0.85,100,100), numbers[digit3]);
      GUI.DrawTexture(Rect(Screen.width*0.12,Screen.height*0.85,100,100), numbers[digit4]);
        
        }      
   
 }
Comment
Add comment · Show 1 · 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 05, 2014 at 10:38 PM 0
Share

I re wrote the whole code i think this is much better than what i had previously.

avatar image
0

Answer by Bunny83 · Feb 06, 2014 at 10:54 AM

There's a much easier solution. Just use your original code and change line #23 to:

     var s:String = TotalPoints.ToString("D4");
Comment
Add comment · Show 1 · 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 07, 2014 at 05:47 AM 0
Share

O$$anonymous$$ thank you!, but how can I deactivate the unused zeros ....???this just flips the order from right to left

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

Load next level after reaching a number 1 Answer

Get set of Pixels from PolygonCollider2d Position 0 Answers

Long looping animated backgrounds in a 2D game. 1 Answer

Why can't I use Texture2D? 1 Answer

Pixel perfect sampling in surface shader 1 Answer


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