InGameMenu.OnGUI C# (CSharp) Method

OnGUI() public method

public OnGUI ( ) : void
return void
	void OnGUI() {

		// Screen percentage: 50% of the screen.
		int screenWidth50  = Screen.width / 2;
		int screenHeight50 = Screen.height / 2;
		
		// Box position.
		var boxWidthPosition  = screenWidth50 - BOX_WIDTH / 2;
		var boxHeightPosition = screenHeight50 - getBoxHeight(enumLength) / 2;
		
		if(isMenuPressed)
		{
			// Drawing the Box.
			GUI.Box(new Rect(boxWidthPosition, boxHeightPosition, BOX_WIDTH, getBoxHeight(enumLength)), /*"Main Menu"*/"");

			// Drawing the Buttons.
			for (int i = 0; i < enumLength; i++)
			{
				if (GUI.Button(new Rect (screenWidth50 - BUTTON_WIDTH / 2, boxHeightPosition + (i * BUTTON_HEIGHT) + ((i + 1) * SPACE_BUTTONS), BUTTON_WIDTH, BUTTON_HEIGHT), names[i]))
				{
					/* Need to add an implementation for each (new) button in "menuButtons"-enum. */

					// Resume
					if (string.Equals(names[i], System.Enum.GetName(typeof(menuButtons), menuButtons.Resume)))
					{
						isMenuPressed = false;
					}

					// Options
					if (string.Equals(names[i], System.Enum.GetName(typeof(menuButtons), menuButtons.Options)))
					{
						Debug.Log("Options-button pressed; no implementation yet.");
					}

					// Quit
					if (string.Equals(names[i], System.Enum.GetName(typeof(menuButtons), menuButtons.Quit)))
					{
						Application.Quit();
					}
				}
			}
		}
	}
}