- Home /
Change in functionality in windows build
Note: I fixed the problem below. It turns out that I had the anchors set up incorrectly, and the wrong animation was set as the default, resulting in the problems I was seeing in the build (which was running at a different resolution than the default set in the editor).
Original:
I'm learning to use the new UI by adding animated buttons for the main menu and the pause menu of a simple game. On loading the main menu, the buttons slide in from the top or the bottom, and on clicking play, the buttons slide out before the new scene loads. In game, if I press escape, I activate a UI image that darkens the screen, and the pause buttons slide in from the top and the bottom, and slide out when I resume the screen. The tutorial I used to learn the basics of the animated main menu is found here: http://www.raywenderlich.com/79031/unity-new-gui-tutorial-part-2
In the Unity editor, everything is working great. When I build the game, however, things don't work correctly. Instead of sliding off the screen at a constant size, the buttons swell as they approach the edge, as if they were lifting off and coming towards the viewer. In game, when I click escape, the pause menu only shows up half the time- sometimes the UI image darkens the screen for half a second before deactivating again, other times the buttons slide in before sliding directly out again and unpausing. These buttons are also doing swelling thing as well.
Any idea why the code would work in the editor, but not in the built exe? I have the regular and the x64 build options, and both act the same.
My code, if it is useful for diagnosis:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class UIManagerScriptGame : MonoBehaviour {
static public UIManagerScriptGame S;
public bool paused = false;
public GameObject menuButton;
public GameObject resumeButton;
public GameObject pauseScreen;
public float delayTime = 0.5f;
private Animator menuAnimator;
private Animator resumeAnimator;
void Awake() {
S = this;
menuAnimator = menuButton.GetComponent<Animator> ();
menuAnimator.enabled = false;
resumeAnimator = resumeButton.GetComponent<Animator> ();
resumeAnimator.enabled = false;
ActivateMenu ();
}
public void MainMenu() {
menuAnimator.SetBool ("isHidden", true);
resumeAnimator.SetBool ("isHidden", true);
Invoke ("MenuNow", delayTime);
}
public void Resume() {
menuAnimator.SetBool ("isHidden", true);
resumeAnimator.SetBool ("isHidden", true);
paused = false;
Invoke ("ActivateMenu", delayTime);
}
void ActivateMenu () {
Button menu = menuButton.GetComponent<Button> ();
menu.interactable = this.paused;
Button resume = resumeButton.GetComponent<Button> ();
resume.interactable = this.paused;
pauseScreen.SetActive (this.paused);
}
void MenuNow() {
Application.LoadLevel ("MainMenu");
}
void FixedUpdate (){
if (Input.GetKeyDown (KeyCode.Escape) && !paused) {
if(!menuAnimator.enabled)
{
menuAnimator.enabled = true;
resumeAnimator.enabled = true;
}
paused = true;
ActivateMenu();
menuAnimator.SetBool ("isHidden", false);
resumeAnimator.SetBool ("isHidden", false);
} else if (Input.GetKeyDown (KeyCode.Escape) && paused) {
paused = false;
menuAnimator.SetBool ("isHidden", true);
resumeAnimator.SetBool ("isHidden", true);
Invoke ("ActivateMenu", delayTime);
}
}
}
Your answer
Follow this Question
Related Questions
How to trigger a button click from script 3 Answers
GUI.FocusControl not working in android? 0 Answers
Unity 4.6 ui scroll rect won't show up in fullscreen 1 Answer
Unity 4.6 UI - Image type conflict 1 Answer
Canvas Scaler appears to crash my game. 0 Answers