GUILabel won´t show up. Help please!!!

Guys…

I have this code, overhere… but when I press on the button it suposse to say on the screen Blocked. Play Mission to unblock. But when I do it, there´s nothing coming up. What is wrong? (I have the GUIStyle as normal, Arial, 20, Black)

void OnGUI()
    {
        GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), galleryTexture);

        if (BossBool._luna)
        {
            if (GUI.Button(new Rect(Screen.width * .15f, Screen.height * .15f, Screen.width * .10f, Screen.height * .14f), "", moonBoss))
            {
                //Add Boss description
            }
        }
        else
        {
            if (lSel == 1)
            {
                if (GUI.Button(new Rect(Screen.width * .15f, Screen.height * .15f, Screen.width * .10f, Screen.height * .14f), "MOON\nBOSS"))
                {
                    GUI.Label(new Rect(Screen.width * .25f, Screen.height * .7f, Screen.width * .5f, Screen.height * .2f), "BLOCKED. PLAY MISSION TO UNBLOCK", bloked);
                }
            }
}

lSel is an integer that I use to get the PlayerPrefs with the languaje selection

Does the GUI.Label ever get actually called? This is the first thing to check so debug or place a Log call in the same code block.

You are right. it is not… what is wrong with the button, then?

As a matter of fact, if I set the BossBool._luna as true, the other button does not work either. Why?

Ok. I got that; It was because of the GUITexture that I have not setted up… so, now, the Debug.Log(“hello”); is working, but the GUILabel still not showing up

Try to simplify the GUI.Label call:

GUI.Label(new Rect(0, 0, 100, 100), "BLOCKED. PLAY MISSION TO UNBLOCK");

And if that works then go step by step: change coordinates, add style till you find out where it goes wrong.

In your code the label height might be a negative value from what I can see.
Log the “Screen.width * .25f” and the rest of the rect values and see if they are what you expect.

This is so sad, hehehe… I did. I tried 0, 0, 100, 100 and I also logged “Screen.width * .25f”… results still the same. first one did not appear and second one is 186.50 in a 5:4 resolution.

Is it because of the conditional? I mean… it never happened before, but maybe a GUILabel cant be inside a conditional… there´s nothing else I can think of…

Maybe the 2 things cant work together…I mean the button and the Label… because if I try the Label before I place any buttons, it is there, but, it does not work when I want it to appear after pressing the button

Can you show the code you have now including the Log call that shows you that the GUI.Label method gets called?

Cannot put the label inside that button if condition,
make a bool value, set it to true when button is clicked,
then (outside that button code) check if that bool is true, show label there

1 Like

Right. So the problem is that the button condition will be triggered once after the button was clicked and so the label gets rendered but only once - on a single frame.
Like mgear said you need to set a flag that will persist beyond that frame and set it’s value upon button click.

1 Like

Great. I´ll try it now. Thanks guys!

Works fine now. Thanks!!!