- Home /
 
 
               Question by 
               Alan Fletcher · Feb 20, 2013 at 02:14 PM · 
                c#guiscorecounter  
              
 
              Make a custom score counter in unity with c#
Hello I am trying to create a custom score counter in unity, currently I am using the below code to create the score counter.
 `void OnGUI () {
          GUILayout.BeginArea ( new Rect( Screen.width/2-Screen.width / 8, 10, Screen.width / 4, Screen.height / 4 ) );
             GUILayout.Box ( score.ToString () );
          GUILayout.EndArea ();
      }`
 
               What i am trying to achieve is like a a digital clock type counter, so there would be an image of the of the background then the number in the center of that background would change as score increased. I would also like to implement a sort of flick down as if you turned a page in a notebook type effect when the score increased.
Any help with completing this is appreciated
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Alan Fletcher · Feb 20, 2013 at 04:34 PM
 public GUITexture textureScore;
 public Texture2D zero;
 public Texture2D one;
 public Texture2D two;
 public Texture2D three;
 public Texture2D four;
 public Texture2D five;
 void Update () {
     if(score == 0){
         textureScore.guiTexture.texture = zero;     
     }else if(score == 1){
         textureScore.guiTexture.texture = one;              
     }else if(score == 2){
         textureScore.guiTexture.texture = two;              
     }else if(score == 3){
         textureScore.guiTexture.texture = three;                
     }else if(score == 4){
         textureScore.guiTexture.texture = four;             
     }else if(score == 5){
         textureScore.guiTexture.texture = five;             
     }
 }
 
               not perfect but it works, no animation on it though
Your answer