No appropriate version of 'UnityEngine.GUI.Box' for the argument list '(UnityEngine.Rect)' was found.

Hey Everyone, I have a problem with my script here. I want my player to collide with the box collider and a GUI window pops up. Here is the script.

function OnTriggerEnter()
{
	GUI.Box(Rect(100,100,100,100));
}

I would appreciate any help and maybe a little help on the OnTriggerEnter function? Thanks again!

You need to go back and do some research.

  • You can only make GUI calls from within the OnGUI() function.
  • There is no GUI.Box() call with just a Rect as a parameter. There are several forms of this call, but you at least have to have a string as a second parameter. It can be an empty string…
  • OnTriggerEnter() is only called for a single frame, so even if your code did work, you would have only seen the box for a single frame. What you might want:

#pragma strict

private var showBox;

function OnTriggerEnter() {
    showBox = true;
}

function OnGUI() {
    if (showBox) {
        GUI.Box(Rect(100,100,100,100),"");
    }
}