// do switching of the buttons on LateUpdate to avoid multiple click throughs void LateUpdate() { if (buttonIsHighlighted && (horizontalValue != 0.0f || verticalValue != 0.0f) && buttonReleased) { //float maxValue = 0.0f; if (Mathf.Abs(verticalValue) < Mathf.Abs(horizontalValue)) { if (horizontalValue < 0.0f && leftPressMenuButton != null) { buttonIsHighlighted = false; activateButton = false; SwitchTexture(); // deactivate state leftPressMenuButton.HighlightButton(); //Debug.Log("activate left"); } else if (horizontalValue > 0.0f && rightPressMenuButton != null) { buttonIsHighlighted = false; activateButton = false; SwitchTexture(); rightPressMenuButton.HighlightButton(); //Debug.Log("activate right"); } } else { if (verticalValue > 0.0f && upPressMenuButton != null) { buttonIsHighlighted = false; activateButton = false; SwitchTexture(); // deactivate state upPressMenuButton.HighlightButton(); //Debug.Log("activate up"); } else if (verticalValue < 0.0f && downPressMenuButton != null) { buttonIsHighlighted = false; activateButton = false; SwitchTexture(); downPressMenuButton.HighlightButton(); //Debug.Log("activate down"); } } } else if (buttonIsHighlighted && activateButton) { Debug.Log(gameObject.name + ": MenuButton: activate button"); if (activateMenuController != null) { activateButton = false; buttonIsHighlighted = false; SwitchTexture(); activateMenuController.ActivateMenu(); Debug.Log(gameObject.name + ": MenuButton: activate menu controller " + activateMenuController.gameObject.name); } else if (startNewGame != null) { activateButton = false; buttonIsHighlighted = false; startNewGame.StartLevel(); Debug.Log(gameObject.name + ": MenuButton: start a new game."); } else { activateButton = false; Debug.LogWarning(gameObject.name + ": MenuButton: no button activation behavior defined"); } } }