Hello Guys,
I’m Florian (14) and I come from the Netherlands.
I’m making a MazeGame (my first game). But I have a problem:
I have made that as you finished the level, you get a screen with a custom box.
And I want that also for a button only it doesn’t work.
This is my script:
var finished:boolean = false;
var BoxTexture:Texture;
var ButtonTexture:Texture;
functionOnTriggerEnter()
{
Debug.Log("YouWin!");
finished = true;
}
functionOnGUI()
{
if (finished)
{
GUI.Box (newRect (Screen.width /2 - 262.5,Screen.height /2 - 337.5,525,675), BoxTexture);
if (GUI.Button (Rect (Screen.width/2 -180,Screen.height/2 +200,350,70), ButtonTexture);
{
Debug.Log ("Restart Button clicked");
Application.LoadLevel ("MazeGameTest");
}
}
}
I think i'm not using the right variable for the buttontexture.
I hope you can help me, and i'm sorry about my bad English :)
hi, please use [code ][/code ] tags when pasting code into the forums, it helps with the readability and adds in line numbers which help us see where errors are occurring when you also include the full error. There is a sticky on them at the top of the scripting forum (there is an option in the text editor but it’s hidden away :().
If you are learning unity for the first time you really should look at the new UI system brought in recently in unity 4.6+. It replaces the old OnGUI approach and is far more intuitive and performant. You build the UI you want in the scene view and can lay it out as you like
rather than trying to create it all through code.
start here: Learn game development w/ Unity | Courses & tutorials in game design, VR, AR, & Real-time 3D | Unity Learn
(your english is fine btw
)
if you want to know why the code above isn’t working, you don’t need “;” at the end of the if.
if (GUI.Button (Rect (Screen.width/2 -180,Screen.height/2 +200,350,70), ButtonTexture);
{
// should be
if (GUI.Button (Rect (Screen.width/2 -180,Screen.height/2 +200,350,70), ButtonTexture)
{
Thanks for the tip.
But do you know the problem what I made in the script?
Now i got the problem:
Assets/Scripts/finish.js(19,17): BCE0044: expecting ), found ‘{’.
I know what that means but I don’t know how to fix that.
Because if i get rid of that i get other problems.
line 16 has 3 opening brackets, but only 2 closing, add a closing bracket on the end