Is there a properly written script for the GUI section of the 3D platformer tutorial. I’ve nothing to compare it to. I think I’m close but am still getting error messages.
New to JavaScript and have scripted, or noodled in some proprietary languages. So I’m not 100% confident.
Any help would totally rock as I’ve been stuck in the GUI section for some time.
If you want help with particular errors, you’ll need to post the code and the error you’re receiving for us to help you.
http://unity3d.com/support/resources/unite-presentations/in-game-gui-made-easy
Check out that video. You’ll be up to speed on Unity’s GUI in no time flat.
Thank you so much for the help and direction.
Just in case I thought I’d upload my script and the error message is below.
ArgumentException: You can only call GUI functions from inside OnGUI.
The Script:
// Links the LerpzTutorialSkin asset
var gSkin : GUISkin;
// our backdropimage goes in here
var backdrop : Texture2D;
// if true, we'll display the "loading..." message
private var isLoading = false;
// the backdrop
var backgroundStyle : GUIStyle = new GUIStyle();
// code checks to see if we have a valid GUI Skin Object
function OnGUI ()
{
if (gSkin)
GUI.skin = gSkin;
else
Debug.Log("StartMenuGUI: GUI Skin object missing!");
if (GUI.Button( Rect( (Screen.width/2)-70, Screen.height - 160, 140, 70), "Play"))
{
isLoading = true;
Application.LoadLevel("TheGame"); // load the game level.
}
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");
}
}
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), "Lerpz Escapes",
"mainMenuTitle");
var isWebPlayer = (Application.platform == RuntimePlatform.OSXWebPlayer ||
Application.platform == RuntimePlatform.WindowsWebPlayer);
// Make the script also execute in edit mode
@script ExecuteInEditMode()
If anyone could check out my script I’d appreciate it.
Thanks again!!!
293635–10458–$startmenugui_156.js (1.3 KB)
The problem is that the closing curly brace just before
backgroundStyle.normal.background = backdrop;
…actually closes the OnGUI function. The remaining code executes outside that function, hence the error. You need to remove that brace and reposition it just before the line:-
var isWebPlayer = (Application.platform...
Can you put up the fixed script? If yes thanks so much!