Game Development Reference
In-Depth Information
Congratulations! By adding this line of code to the OnGUI() method, you will display
a button at the x and y position with the text "string" on the button.
Detecting a mouse click
To detect a mouse click on this button, we need to check that the GUI.Button()
function returns a Boolean; namely, true when the button is clicked and false oth-
erwise. This means that every time the OnGUI() method is called, we have the op-
portunity to respond to a mouse click, each time a button is potentially drawn to the
screen:
if (GUI.Button( new rect(x,y,width,height),
string))
{
// handle button click here
}
Search WWH ::




Custom Search