Search Unity

Counting With GUITextures

Discussion in 'Scripting' started by platonia96, Oct 23, 2011.

  1. platonia96

    platonia96

    Joined:
    Mar 10, 2010
    Posts:
    225
    Hey guys,

    So I'm having some trouble finding the correct way to do this.
    Basically, you will collect objects throughout the world (wisps) and i want to have an on-the-gui counter for these objects.
    The GUI will feature four GUITexture objects positioned next to each other, one representing the ones place, tens place, hundredths place, and thousandths place. Currently, i am trying to add the number of colored "wisps" together to get the
    "score". How can i assign the ones place from the integer in the score to the ones GUITexture, tens to tens, etc..?

    Here is the code i have right now...

    Code (csharp):
    1. var g0 : Texture2D;
    2. var g1 : Texture2D;
    3. var g2 : Texture2D;
    4. var g3 : Texture2D;
    5. var g4 : Texture2D;
    6. var g5 : Texture2D;
    7. var g6 : Texture2D;
    8. var g7 : Texture2D;
    9. var g8 : Texture2D;
    10. var g9 : Texture2D;
    11.  
    12. var scoreOnes : int;
    13. var scoreTens : int;
    14.  
    15. var numberOnes;
    16. var numberTens;
    17. var numberHundreds;
    18. var numberThousands;
    19.  
    20. //Gui Stuff
    21. var skin : GUISkin;
    22.  
    23. private var originalWidth = 1280.0;
    24. private var originalHeight = 800.0;
    25.  
    26. private var scale: Vector3;
    27.  
    28. function LateUpdate () {
    29.    
    30.     Conversion();
    31.  
    32. }
    33.  
    34. function Update () {
    35.    
    36.     receiver = GameObject.FindWithTag("CollectionManager").GetComponent(CollectingFollowersReceiver);
    37.    
    38.     scoreOnes = receiver.greenCnt + receiver.purpleCnt + receiver.blueCnt + receiver.yellowCnt + receiver.whiteCnt;
    39.  
    40. }
    41.  
    42. function OnGUI () {
    43.    
    44.     scale.x = Screen.width/originalWidth;
    45.     scale.y = Screen.height/originalHeight;
    46.     scale.z = 1;
    47.    
    48.     GUI.skin = skin;
    49.    
    50.     var svMat = GUI.matrix;
    51.  
    52.     GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);
    53.  
    54.     GUI.Box(Rect(100,0,230,50), "");
    55.    
    56.     GUI.DrawTexture(Rect(250,0,50,50), numberOnes);
    57.    
    58.     GUI.DrawTexture(Rect(210, 0, 50, 50), numberTens);
    59.    
    60.     GUI.matrix = svMat;
    61.    
    62. }
    63.  
    64. function Conversion () {
    65.    
    66.     if(scoreOnes == 0) {
    67.         numberOnes = (g0);
    68.            
    69.     }
    70.    
    71.     if (scoreOnes == 1) {
    72.         numberOnes = (g1);
    73.     }
    74.    
    75.     if (scoreOnes == 2) {
    76.         numberOnes = (g2);
    77.        
    78.     }
    79.    
    80.     if (scoreOnes == 3) {
    81.         numberOnes = (g3);
    82.        
    83.     }
    84.    
    85.     if (scoreOnes == 4) {
    86.         numberOnes = (g4);
    87.        
    88.     }
    89.    
    90.     if (scoreOnes == 5) {
    91.         numberOnes = (g5);
    92.        
    93.     }
    94.    
    95.     if (scoreOnes == 6) {
    96.         numberOnes = (g6);
    97.        
    98.     }
    99.    
    100.     if (scoreOnes == 7) {
    101.         numberOnes = (g7);
    102.        
    103.     }
    104.    
    105.     if (scoreOnes == 8) {
    106.         numberOnes = (g8);
    107.        
    108.     }
    109.    
    110.     if (scoreOnes == 9) {
    111.         numberOnes = (g9);
    112.  
    113.     }
    114.  
    115.     if (scoreOnes == 10) {
    116.        
    117.         scoreOnes = 0;
    118.         numberOnes = (g0);
    119.         scoreTens = scoreTens + 10;
    120.        
    121.     }
    122.        
    123.     if (scoreTens == 0) {
    124.            
    125.         numberTens = (g0);
    126.                    
    127.         }
    128.        
    129.     if (scoreTens == 10) {
    130.        
    131.         numberTens = (g1);
    132.        
    133.     }
    134.    
    135.     if (scoreTens == 20) {
    136.        
    137.         numberTens = (g2);
    138.        
    139.     }
    140.    
    141.     if (scoreTens == 30) {
    142.        
    143.         numberTens = (g3);
    144.        
    145.     }
    146.    
    147.     if (scoreTens == 40) {
    148.  
    149.         numberTens = (g4);
    150.        
    151.     }
    152.    
    153.     if (scoreTens == 50) {
    154.        
    155.         numberTens = (g5);
    156.        
    157.     }
    158.    
    159.     if (scoreTens == 60) {
    160.        
    161.         numberTens = (g6);
    162.        
    163.     }
    164.    
    165.     if (scoreTens == 70) {
    166.        
    167.         numberTens = (g7);
    168.        
    169.     }
    170.    
    171.     if (scoreTens == 80) {
    172.        
    173.         numberTens = (g8);
    174.        
    175.     }
    176.    
    177.     if (scoreTens == 90) {
    178.        
    179.         numberTens = (g9);
    180.        
    181.     }  
    182. }
    Any help would be greatly appreciated. Thanks in advance.