Game Development Reference
In-Depth Information
}
}
6. Next, we will create a draggable window menu, which will contain all the buttons
and background textures; add this code after the OnGUI function as follows:
// Unity JavaScript user:
private function DoMyWindow (windowID : int) : void {
_currentTool = GUI.Toolbar (TAB_BTN_RECT,
parseInt(_currentTool), TOOLBARS,
GUI.skin.GetStyle("Tab Button"));
GUI.DrawTexture(HERO_RECT, heroTexture);
if (GUI.Button (CLOSE_BTN_RECT, "",
GUI.skin.GetStyle("Exit Button"))) {
_isMenuOpen = false;
Time.timeScale = 1.0f;
}
GUI.DragWindow();
}
// C# user:
void DoMyWindow (int windowID ) {
_currentTool = (TAB) GUI.Toolbar (TAB_BTN_RECT,
(int)_currentTool, TOOLBARS, GUI.skin.GetStyle("Tab
Button"));
GUI.DrawTexture(HERO_RECT, heroTexture);
if (GUI.Button (CLOSE_BTN_RECT, "",
GUI.skin.GetStyle("Exit Button"))) {
_isMenuOpen = false;
Time.timeScale = 1.0f;
}
GUI.DragWindow();
}
7. Then, we go back to the OnGUI function. We will add the code to create a drag-
gable window by using GUI.Window and passing the DoMyWindow() func-
tion that we just created. We also make sure that the window is always on the
Search WWH ::




Custom Search