GUI and other Commands

Hello all,

please, somebody know how Unity can read commands between GUI and other commands? I mean, I want my player to press the button “Fire1” (whatever) and then a message on screen should appear where I want (I thought this could be done with GUI class/commands).

Thanks in advance.

if(Input.GetKey("Fire1"))
  GUI.Label(...)

within your OnGUI callback.
GUI.xxx is only allowed in there

I tried this already, it says to me that that command can only be used inside OnGUI…is that what you said?

What do you mean with “within your OnGUI callback.” ?

Thanks :wink:

He means that within your script you need a on gui function which should look like.

function OnGUI() 
{ 
// Do your stuff here.
}

You could also call function from your OnGUI function to just seperate menus for a smaller function example.

C#

public void OnGUI()
{
// Create a button
CreateButton();
}

public void CreateButtion()
{
   if ( GUI.Button.... etc)
      {
        // Do something.
      }
}

Thanks :smile: