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

Custom Texture for Score Board

Discussion in 'Scripting' started by Hansuke, Aug 22, 2008.

  1. Hansuke

    Hansuke

    Joined:
    Apr 17, 2007
    Posts:
    100
    Code (csharp):
    1. static var scorepoints: int = 0;
    2.  
    3. function AddToScore() {
    4.     scorepoints++;
    5. }
    6.    
    7. function OnGUI() {
    8.     GUI.Label(Rect(970, 0, 500,500),"Points ="+scorepoints.ToString());
    9. }
    10.    
    This code is actually working, but im wondering how am i suppose to put a custom 2D Texture instead just normal text for the Score Board?
     
  2. GargerathSunman

    GargerathSunman

    Joined:
    May 1, 2008
    Posts:
    1,571
    If you want a custom texture for the text, you need to get yourself a font. If you want a 2D texture background, just add:

    GUI.Box(Rect(970,0,500,500), customTexture);
     
  3. Hansuke

    Hansuke

    Joined:
    Apr 17, 2007
    Posts:
    100
    ah its working great now, thanks !


    Code (csharp):
    1. static var scorepoints: int = 0;
    2. var windowRect : Rect = Rect (20, 20, 120, 50);
    3.  
    4. function AddToScore() {
    5.     scorepoints++;
    6. }
    7.        
    8. function OnGUI () {
    9.     windowRect = GUI.Window (1, windowRect, BringWindowToBack, "SCORE BOARD");
    10. }
    11.  
    12. function BringWindowToBack (windowRect : int) {
    13.     guiText.text = "Points : " +scorepoints.ToString();
    14. }
    The guiText is showing behind the window, any idea how to bring it to front so it doesnt stay at the back of the window?