Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 tolgaguducu · Aug 03, 2015 at 07:25 PM · guispritehow tonumbers

How can I use sprites as numbers?

I have 0-9 numbers as sprites. I dont want to show score with text. I want to show the score with those sprite numbers 0-9? and it should be for example 17 like 1-7. is it possible to do it? or i can do it by using only fonts?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Dave-Carlile · Aug 03, 2015 at 07:27 PM

Yep, you can do this. It's a little work though. The basic idea is that you get each digit of the number which will be from 0 through 9, and use that as an index into an array of prefabs for the equivalent digit image...

 // initialize a sprites array with the a prefab for for each digit,
 // making sure the 0 index points to the 0 sprite image, and the 9 index
 // points to the 9 sprite image - left as an exercise for the reader - 
 // should be able to do this in the editor if you make it a public property

 GameObject[] sprites = new GameObject[10]
 
 int value = 4143;  // make sure the data type is an integer
 
 // this is the key part, converting an integer score into your sprites
 while (value > 0)
 {
   // get the 1's place value - % is the modulo operator which
   // divides by the the specified value and returns the remainder, 
   // e.g. 4143 % 10 = 414 with a remainder of 3, so it returns the value 3
   // which is the digit in the 1's place
   int digit = value % 10;
 
   // TODO : create and position sprite instance from sprites[digit]
   // remember that we're going from the right to left
 
   // move the 10's place to the 1's place
   // the first time through value is 4143, so dividing by 10 gives us 414
   value /= 10;
 }

Note that you're building things from right to left - i.e. each time through the loop you're getting the value in the ones place. You'll have to have a special case where value starts out at 0. And maybe some other edge cases I didn't think of. But this should give you the basic idea.

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

I ask one thing about resizing with different resolution. 1 Answer

Sprites and minmizing memory usage 1 Answer

What to use for dynamic loading of assets instead of Resources.Load()? 1 Answer

Drawing a sprite box and then displaying text over it 0 Answers

Pressing "T" in the Sprite Editor trims the slice. It should only work when pressing "Shift+T". Please help 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