You Win GUI Script

So the last two days i have tried to wrap my head around GUI but i cant seem to get the thing out of it that i want.
The basic idea is that i want a GUI screen to pop up when i touch a certain game object (The orb, if anyone saw my last post) and say “You won” and then show a score and two buttons saying “Play again” and “Continue”.

Anyone out there with some idea how to do this ? :slight_smile:

Try this?
void OnGUI()
{
if(bool)
{
GUI.Label(Rect(Screen.height-10,Screen.width-40,20,80),“You WIN!”);
if(GUI.Button(Rect(Screen.height+40,Screen.width-80,20,20,“Play Again?”);
Application.LoadLevel(yourLevel); or do what ever you want
if(GUI.Button(Rect(Screen.height+40,Screen.width+60,20,20,“Continue”);
again whatever :smile:
}
}
Just adjust the values and have fun btw this should be called when the sphere is touched like through boolean variables

This is a C# script right? Cause i really can’t seem to get it working :S
Here is what i have come up with so far (not that much since i got a lot of errors):

using UnityEngine;
using System.Collections;

void OnGUI(){

if(bool)
{

GUI.Label(Rect(Screen.height-10,Screen.width-40,20,80),“You WIN!”);
if(GUI.Button(Rect(Screen.height+40,Screen.width-80,20,20,“Play Again?”);
Application.LoadLevel(1);
if(GUI.Button(Rect(Screen.height+40,Screen.width+6,0,20,20,“Continue”);
}
}

And which errors?

Always, if you getting errors, post the errors in the thread! (The more information (error-notes) you publish, the more help you will get.)

1 Like

These if blocks have a number of problems:

if(GUI.Button(Rect(Screen.height+40,Screen.width-80,20,20,"Play Again?");
Application.LoadLevel(1);
if(GUI.Button(Rect(Screen.height+40,Screen.width+6 ,0,20,20,"Continue");

Open parens should always have matching close parens and they shouldn’t end with semi-colons. This should be closer:

if(GUI.Button(Rect(Screen.height+40,Screen.width-80,20,20),"Play Again?"))
{
   Application.LoadLevel(1);
}
if(GUI.Button(Rect(Screen.height+40,Screen.width+6 ,0,20,20),"Continue"))
{
  // do somethig here
}

Ok so after doing what Jgodfrey wrote i still get a couple of errors:

First here is the code in question:

using UnityEngine;
using System.Collections;

void OnGUI(){

if(bool)
{

GUI.Label(Rect(Screen.height-10,Screen.width-40,20,80),"You WIN!");
if(GUI.Button(Rect(Screen.height+40,Screen.width-80,20,20),"Play Again?"))
{
   Application.LoadLevel(1);
}
if(GUI.Button(Rect(Screen.height+40,Screen.width+6 ,0,20,20),"Continue"))
{
  // do somethig here
}
}
}

And the errors i get is:

Error 1:
Assets/2DProject/Scripts/YouWin.cs(6,8): error CS1525: Unexpected symbol )', expecting .’

Error 2:
Assets/2DProject/Scripts/YouWin.cs(4,6): error CS0116: A namespace can only contain types and namespace declarations

Error3:
Assets/2DProject/Scripts/YouWin.cs(19,1): error CS8025: Parsing error

Oh and thank you guys for such a quick response :slight_smile: it really helps

A good first question to ask yourself would be, what do you think this line:

if(bool)

Is intended to do?