Game Development Reference
In-Depth Information
screen by checking the
x
and
y
positions of
_windowRect
, so add the follow-
ing highlighted code to the
OnGUI
function.
// Unity JavaScript user:
function OnGUI () : void {
…
if ((e.isKey) && (e.keyCode == KeyCode.M) &&
(!_isMenuOpen)) {
…
}
if (_isMenuOpen) { //Open menu if 'true'
_windowRect = GUI.Window (0, _windowRect,
DoMyWindow, "");
_windowRect.x = Mathf.Clamp(_windowRect.x, 0.0f,
Screen.width - _windowRect.width);
_windowRect.y = Mathf.Clamp(_windowRect.y, 0.0f,
Screen.height - _windowRect.height);
}
}
// C# user:
void OnGUI () {
…
if ((e.isKey) && (e.keyCode == KeyCode.M) &&
(!_isMenuOpen)) {
…
}
if (_isMenuOpen) { //Open menu if 'true'
_windowRect = GUI.Window (0, _windowRect,
DoMyWindow, "");
_windowRect.x = Mathf.Clamp(_windowRect.x, 0.0f,
Screen.width - _windowRect.width);
_windowRect.y = Mathf.Clamp(_windowRect.y, 0.0f,
Screen.height - _windowRect.height);
}
}