drawing a box with GUI

function OnGUI() { 

print(""+boxselecting);

if(boxselecting){

    var width : int = leftupbox.x - rightdownbox.x;

    var height : int = (Screen.height - leftupbox.y) - (Screen.height - rightdownbox.y);

    var rect : Rect = Rect(rightdownbox.x, Screen.height - rightdownbox.y, width, height);

    //GUI.Box(rect, "Its ALIVE");

    GUI.Box(Rect(rightdownbox.x, Screen.height - rightdownbox.y, width, height), "Its ALIVE");

    //GUI.DrawTexture(rect, selectionTexture, ScaleMode.StretchToFill, true, 10.0f);

    print("GUI");

}
} 

this is my code for drawing a box and unity gives me the GUI can only be called in OnGUI error whats wrong with my code?

I don't know how well you pasted this piece of code but your "function OnGUI()" is missing the "f".

If thats the same as in your code that thats prob the problem?

You have to Post the entire code to ascertain what is going wrong where. Have you called any other GUI object or referenced any GUI element from any other function. If so, remove that.

I found GUI.Box() to be very trap-laden, my solution was to eschew it entirely, and just use GUI.DrawTexture() with a 1x1 colored texture image.