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

How to move GuiText to front?

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

  1. Hansuke

    Hansuke

    Joined:
    Apr 17, 2007
    Posts:
    100
    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 seems to appear behind the gui window...how to bring it to front ?

    Ernest
     
  2. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Um, you cant mix the GUI types..

    guiText is the old gui system that is not part of the OnGUI stuff. guiText is a gameobject that you move forward/back in depth using its transform.z position, like any other gameobject.

    Stuff inside OnGUI will always be drawn over the viewport.

    You want to change the guiText.text stuff to be...

    Code (csharp):
    1. function BringWindowToBack (windowRect : int) {
    2.    GUI.Label(Rect(0,0,100,50), "Points : " +scorepoints.ToString());
    3. }
     
  3. Hansuke

    Hansuke

    Joined:
    Apr 17, 2007
    Posts:
    100
    but im using a custom font + texture for the GuiText...how can i implement it into OnGUI functions?
     
  4. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    You can make GUISkins... read up on your documentation, or search the forums here for info about how to do it,

    The new GUI system is VERY flexible, once you learn how to use it all.
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    GUISkins are limited to using mono-colored TTF fonts, though. If you need to control how stuff is layered, like Seon said, you can't mix OnGUI with GUIText...use one or the other.

    --Eric
     
  6. Hansuke

    Hansuke

    Joined:
    Apr 17, 2007
    Posts:
    100
    hmm alright :) Thanks !