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 Tricky7991 · Jul 11, 2021 at 05:11 PM · scoreboard

ScoreBoard Counter Problems

I'm racking my brains at this and I am guessing I am over looking the simple solution. Searching for answers and haven't found one that works with what i am trying to do.

I have a score counter, it is using UI.Images for each number. Tried different methods which all turned into errors for me.

I have a Index of 0-9 sprites, and 6 "sections" that need to change.

scoreboard

Basically, if the score is 980345, it needs to display from 0 to 5 in the sections.

scoreboardfull

 scoreUIImage0.sprite = ui_Numbers[playerman.playerScore % 10];

Using that script will make the "0" slot work. But breaks for the rest of the slots. I am probably not using it correctly

score.png (19.7 kB)
scorep.png (31.0 kB)
Comment
Add comment · Show 4
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 lucasjohansson · Jul 11, 2021 at 07:08 PM 0
Share

So in the end, the score will look reversed?

avatar image Tricky7991 lucasjohansson · Jul 11, 2021 at 08:17 PM 0
Share

No, The reason its going right to left is how its displayed on on the hud. Basically, I have the score int. I just need to be able to pick each number from the int.

So, if the score is 123456. each number will go in each slot compared to the position. I need to get each number from the int and use them to display in the correct slot the correct number.

I could do this easily by using Text. But I want to be able to use a image. I already have it working for single digits.

Hopefully I am explaining this well enough.

avatar image rh_galaxy · Jul 12, 2021 at 08:43 PM 0
Share
 scoreUIImage0.sprite = ui_Numbers[(playerman.playerScore/1) % 10];
 scoreUIImage1.sprite = ui_Numbers[(playerman.playerScore/10) % 10];
 scoreUIImage2.sprite = ui_Numbers[(playerman.playerScore/100) % 10];
 scoreUIImage3.sprite = ui_Numbers[(playerman.playerScore/1000) % 10];
 ...

?

avatar image Tricky7991 rh_galaxy · Jul 13, 2021 at 03:30 PM 0
Share

:faceplam: Works perfect, and doesn't take many lines. I knew it was simple. I just couldn't picture what I needed to do. Thanks and if you add it as a answer I will accept it.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by veyseler · Jul 13, 2021 at 07:17 AM

 var str = playerman.playerScore.ToString()
 var len = str.Length;
 var int0 =  Int32.Parse(str[len - 1].ToString());
 scoreUIImage0.sprite = ui_Numbers[int0];

You can apply similar approaches for the rest of the sprites. You are taking mod base 10 so its only working for the last digit. If you wanna go with the math approach you need the divide that playerScore by 10 at each step. Like this you can use the lastDigit as your indexing variable:

 var tempInt = 1234;
 while (tempInt != 0)
 {
     int lastDigit = tempInt % 10;
     tempInt = tempInt / 10;
 }





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 Tricky7991 · Jul 13, 2021 at 03:33 PM 0
Share

Thanks it works like this too! but was trying to keep lines and vars to a $$anonymous$$imum already. And the int to string is what I was trying to do at first and kept getting errors about the array.

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

123 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 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

Creating a scoreboard 1 Answer

How to make an online scoreboard -1 Answers

Access the data of OnTriggerEnter2D function of a script from the other Script, how do I it? 2 Answers

How to Use Leader Board Third Party API ? 2 Answers

I need my script to load and save my players score to a text file . When I attach the script to a gameobject the script either is not found or it just prints 5,4,3,2,1 or all )0's. 0 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