x


How to control OnGUI? (Please help I have no idea what is wrong)

I have no idea what is wrong with this I am trying to get a GUI to pop up giving the player a choice to either go back to the main menu or continue with the tutorial. So I put in the code for it and it gave me three errors that when I do what it says it adds even more errors. Please help because clearly I have no idea what I'm doing so if anyone does help could you please explain what I did wrong thoroughly. Thank you

//This script creates a lap counter that once it reaches 3 it will restart the level

var score:int;

function OnTriggerEnter(other : Collider){

    if (score 
                
more ▼

asked May 08 '12 at 02:38 AM

dwedge gravatar image

dwedge
-19 2 2

You have chosen an awful name for this topic posting.

May 08 '12 at 02:57 AM kolban

I see one of your issues. Youre nesting a function within an else statement. You cant do that, especially a Unity predefined function. You cant place OnGUI() within OnTriggerEnter(). Separate them and see what happens.

May 08 '12 at 03:01 AM GC1983

@kolban is right: this name means nothing! Edited your question and added a more meaningful name.

May 08 '12 at 03:46 AM aldonaletto
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

As @GC83 said, you can't redefine OnGUI inside anoher function. In order to control the GUI, you must have a boolean variable that enables / disables the code inside OnGUI:

var score:int;

private var guiEnable = false;

function OnTriggerEnter(other : Collider){

    if (score 
more ▼

answered May 08 '12 at 03:43 AM

aldonaletto gravatar image

aldonaletto
42.5k 16 43 202

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x168
x122
x39

asked: May 08 '12 at 02:38 AM

Seen: 379 times

Last Updated: May 08 '12 at 03:18 PM