x


calling buttons in triggers

its annoying me that unity wont let me call a GUI Button function in an OnTriggerEnter function after the if statement. I want to make instructions come up when you enter a trigger, but unity tells me that the I can only call GUI functions from inside OnGUI(). any ideas around this?

heres the script so far:

var tips1 : GUIText;
var tipsPREFAB : GUIText;

function OnTriggerEnter (player : Collider) 
{
    if(player.gameObject.name == "BlueMan")
    {
       OnGUI();
    }
}

function OnGUI () 
{
    (GUI.Button (Rect(10, 300, 100, 80), "press T for help "));
}
more ▼

asked Jul 18 '11 at 04:26 PM

Kag359six gravatar image

Kag359six
102 20 31 33

When posting code, make sure it's formatted or people will likely ignore your question. You can see how it's going to look with the preview box as you're writing your question.

Jul 18 '11 at 08:32 PM Chris D
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You'll find lots of info for your problem by searching for "pause menu" and the like in the search box. This one here seems to be a pretty decent solution; just substitute an OnCollisionEnter for the if (Input....) position in Update.

Essentially, whatever you put in OnGUI is going to get called every frame. To get the behaviour you want, you have to enable and disable the buttons/text according to an outside condition.

more ▼

answered Jul 18 '11 at 08:45 PM

Chris D gravatar image

Chris D
2.5k 5 7 25

(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:

x104
x101
x82
x76

asked: Jul 18 '11 at 04:26 PM

Seen: 650 times

Last Updated: Jul 18 '11 at 08:45 PM