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 mealone · Jun 08, 2014 at 07:42 AM · arrayscoreconstrain

help with score display concept

hello, i am trying to make a concept for displaying scores without having to utilize the gui system and at the same time trying to be a bit creative... i am getting some problems with converting my pseudocode concept into actual unity jscript and would greatly appreciate as much help as possible on this issue.

i am trying to create the scores for the game using gameobjects which change the sprite image between the numbers 0 and 9 to demonstrate the score. this is the concept that i have :

  1. create the gameobject with the image of the number 0.

  2. add script to gameobject with sprite variables going from 0-9.

  3. create an integer variable called divider, this will be set to 10 which is the cap or maximum. this means that the gameobject's image can only change from 0-9, or any number under 10, counting down to 0.

  4. constrain the gameobject's sprite image to the current game score, so if the score = 6, the gameobject's sprite image would change to 6, and would be the same for all numbers going from 0-9, so if score = 2 the sprite image would be change to 2 etc... .

i am not sure how to constrain the images to the score however, and would like to use the divider var to be able to switch from tens, to hundreds, to thousands, by changing the variable number in the inspector from 10 to 100, or 1000. so if the var divider is 100 in the inspector, the sprites changing from 1-9 would represent 10 to 90.

in order to show the score of 95 for example, i would need the gameobject "0" on the screen twice in a row, and the first 0 gameobject would represent tens because the variable divider would be set to 100, and the other "0" gameobject would represent ones because the var divider would be set to 10. so when the game score changes from 0 to 95, the first zero gameobject would be constained to the tens portion of the score, and will change to 9, which represents 90, and the second gameobject will change to 5, representing the ones portion of the score. (i hope this is clear)

finally, using the divider variable we will have this code to hide the unused gameobjects by making them invisible.

 if (score.gameScore >= divider){
     renderer.enabled = true;}
     else {renderer.enabled = false;}

so as an example, the maximum that the score can get to is 9,999. we would then add the prefab "0" into the scene four times, and then in the inspector change the var divider to 10,100,1000, and 10,000 on the four prefabs in the scene. the player would start the game and score 250 points, the score during the gameplay would show as "250" instead of showing as "0250" because the score would be less than the the variable divider for the thousands which would be set to 10,000 in the inspector. however if the score is 1500, it would show as "1500" and the gameobject representing the thousands would be visible.

i really hope i explained this properly, and would greatly appreciate any help with this.

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 mealone · Aug 03, 2014 at 01:16 AM

var g0 : Sprite; var g1 : Sprite; var g2 : Sprite; var g3 : Sprite; var g4 : Sprite; var g5 : Sprite; var g6 : Sprite; var g7 : Sprite; var g8 : Sprite; var g9 : Sprite; var numberOnes : Sprite;

function Start () {

}

function LateUpdate () { Conversion(); }

function Update () { GetComponent(SpriteRenderer).sprite = numberOnes; if (score.gameScore >= 10){ renderer.enabled = true;} else {renderer.enabled = false;} }

function Conversion () {

 var ones: int = score.gameScore /10%10;  
 numberOnes = GetDigit(ones);

}

function GetDigit (digit: int): Sprite {

 switch (digit){
     case 0: return g0;
     case 1: return g1;
     case 2: return g2;
     case 3: return g3;
     case 4: return g4;
     case 5: return g5;
     case 6: return g6;
     case 7: return g7;
     case 8: return g8;
     case 9: return g9;
 }

}

this worked for me.

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

Answer by TheGameWizard · Jun 08, 2014 at 10:01 AM

Just make a texture with 0-9 and use UVOffset in the code, to hookup the digits to textures. And regarding your problem with 0250 and 250, you can just disable the box, when its zero.

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

22 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

Related Questions

Array Problem - Error Code BCE0022 2 Answers

Trying to get score counter... 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

help with direction 1 Answer

Is it necessary to create an Array() to show high scores in PlayerPref? 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