Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Ones place, etc in scripting

Discussion in 'Scripting' started by yangmeng, Jun 26, 2007.

  1. yangmeng

    yangmeng

    Joined:
    Dec 5, 2006
    Posts:
    573
    I would like to use original graphics instead of a font to display a score. I need to be able to deal with the ones, tens and hundreds places of the number separately. For the scripting I could say "if score is 5 or 15 or 25" etc, set ones place to the graphic for five, but there should be a more elegant and intelligent way to do, this saying instead "if the ones place is five" or "if the tens place is three" and so on. Does anyone know how to do this with scripting?
     
  2. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    yeah.. make a quicktime movie of your "graphic" numbers from 0 - 9... where each is on their respective frame.

    Then if you need 5 digits for the score, you add 5x guiTextures next to each other using a version of the QT mov, and the logic goes... for each number in the score, cycle the correct digit to the correct frame.

    That way, you can have whatever graphics you want in each frame to represent a digit, or even something like a slot machine... pinapples/bananas, or gems... etc
     
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,777
    First off, I'd like to point out that this is fairly pointless, given that you can create your own font and do about anything you'd want to:
    http://www.unifycommunity.com/wiki/index.php?title=Font_Creation

    That said, you can use modulus to get a particular digit.
    Code (csharp):
    1.  
    2. hundredsPlaceFrame = (score / 100) % 10;
    3. tensPlaceFrame = (score / 10) % 10;
    4. onesPlaceFrame = (score) % 10;
    5.  
     
  4. yangmeng

    yangmeng

    Joined:
    Dec 5, 2006
    Posts:
    573
    Hey, thanks for the tip on the Wiki font info. I think that will come in handy at some point, but right now the code you supplied actually IS what I want for what I am doing, and it's also educational. So thanks for that too.