Search Unity

GUI label does not come up

Discussion in 'Scripting' started by herbie, Sep 10, 2013.

  1. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    Does anybody has an idea why this is not working?
    Code (csharp):
    1. if (Input.GetMouseButtonUp(0))
    2.     {
    3.         GUI.Label(Rect(100,100,300,33), String.Format("Test"), styleBox);
    4.     }
    5.  
    The GUILabel is not coming up when the mousebutton is pressed.
     
  2. surreal4224

    surreal4224

    Joined:
    Apr 10, 2011
    Posts:
    51
    You havnt setup your button correctly and I would not try to do too much with your label at once until you have tested its basic layout first. Stay away from styles and text formating until its functional.

    and always run your gui inside OnGUI () declaration.

    this code is untested, for more reference check the docs.

    Code (csharp):
    1.  
    2.  
    3. if (GUI.Button(Rect (10,10,10,10), "click me")) {
    4.        GUI.Label (Rect (10,10,10,10), "label text");
    5. }
    6.  
    7.  
     
  3. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    GetMouseButtonUp is only true for the frame the button is release. So your label probably does show up but only for one frame. What you probably want is to use a bool flag that is flipped when the user presses the mouse button.
     
  4. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    Yes of course, that's it.
    It's working now. Thanks!