I made this rudimentary main menu based on one of the example projects. It runs just fine when I press the play button in the Unity GUI, but when I actually make a build and run it, it just displays a blank blue screen, as though OnGUI() is not being called.
The script is attached to the main camera in a default/new scene. The scene is set as scene 0 and is checked in my build settings, and it’s the only scene. Anyone know what I did wrong? Thanks.
// Make the script also execute in edit mode
@script ExecuteInEditMode()
var gSkin : GUISkin;
var backdrop : Texture2D; // our backdrop image goes in here.
private var isLoading = false; // if true, we'll display the "Loading..." message.
function OnGUI()
{
if (gSkin)
GUI.skin = gSkin;
else
Debug.Log("StartMenuGUI: GUI Skin object missing!");
var backgroundStyle : GUIStyle = new GUIStyle();
backgroundStyle.normal.background = backdrop;
GUI.Label ( Rect( (Screen.width - (Screen.height * 2)) * 0.75, 0, Screen.height * 2,
Screen.height), "", backgroundStyle);
GUI.Label ( Rect( (Screen.width/2)-197, 50, 400, 100), "Gunzo!",
"mainMenuTitle");
if (GUI.Button( Rect( (Screen.width/2)-70, Screen.height - 160, 140, 70), "Play"))
{
isLoading = true;
Application.LoadLevel("TheGame"); // load the game level.
}
var isWebPlayer = (Application.platform == RuntimePlatform.OSXWebPlayer ||
Application.platform == RuntimePlatform.WindowsWebPlayer);
if (!isWebPlayer)
{
if (GUI.Button( Rect( (Screen.width/2)-70, Screen.height - 80, 140, 70), "Quit"))
Application.Quit();
}
if (isLoading)
GUI.Label ( Rect( (Screen.width/2)-110, (Screen.height / 2) - 60, 400, 70),
"Loading...", "mainMenuTitle");
}
function Update () {
}
Don’t see anything like that. Where would that appear? I only have the Main Camera object.
I have another more complicated scene, and none of my scripts are running in the executable for that scene either. It’s probably something simple that will make me slap my forehead when I find it. :?
I have the exact same problem
try starting a new project and imprt a few scripts like a basic character controllerand stuff any scripts that youve made and make a basic test scene to play in then build it and it should work fine.
then make sure everything in the project is saved and close unity then start it again and load the scene. import a few more scripts and integrate them into the scene and build it again. if this is the same bug i’m having then half your scripts wont work for you on the second build it seems to be when you close unity and reload the project it just stops compiling shit into the build or something for that scene/project. this happened to me one day randomly for no reason at all across all my projects. i even imported scripts from projects that i know to work in the build version and the wont work in the new builds it is wrecking my head.
Edit: I even sent a bug report and they asked for some feedback and to run a few tests with the latest version but to no avail even the Unity devs are clueles to this one.
I copied pasted your code in an empty scene and tried it. Aside the warning about a missing GUISkin, I see the GUI when building the windows standalone. Try leaving your GUISkin variable field empty ?
Yes, starting from scratch and importing my script fixed it. Thanks! I think the problem has something to do with where the script is saved when you create it. At least I think you should be able to save a new script and use it straightaway, if not… user error.
After some experimenting i found that if you simply just delete the previous Build of the level and its acompanying data folder before each new build gives the same results it appears as if it isnt loading scripts into the already compiled files in the folder it would seem