x


SOS. Box collider trigger for audio

have a presentation in a few hours, and im desperate. one of my scripts is acting up.

Basically a Box Collider is hit and audio and text come out.

var stringToEdit = " ";
var showgui:int=0;
var PlayClip:audio.Play;


function OnGUI () {

if (showgui==1){
    // Make a multiline text area that modifies stringToEdit.
    stringToEdit = GUI.TextArea (Rect (10, 10, 300, 100), stringToEdit, 200);audio.Play(PlayClip);
    }
}


function OnTriggerEnter(){
showgui=1;
}

GUI came out but audio was messed up! Whats wrong?

more ▼

asked May 10 '10 at 04:22 AM

ZeNooB gravatar image

ZeNooB
13 2 2 5

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

That code wouldn't actually compile anyway; maybe you wanted something more like this:

var stringToEdit = " ";
var showgui = false;
var playClip : AudioClip;

function OnGUI () {
    if (showgui) {
        // Make a multiline text area that modifies stringToEdit.
        stringToEdit = GUI.TextArea (Rect (10, 10, 300, 100), stringToEdit, 200);
    }
}

function OnTriggerEnter(){
    showgui = true;
    audio.clip = playClip;
    audio.Play();
}

OnGUI runs at least twice per frame, so it's unlikely you want audio.Play() in there.

more ▼

answered May 10 '10 at 04:48 AM

Eric5h5 gravatar image

Eric5h5
81.5k 42 133 529

Thanks so much!! That actually made sense. Do you happen to know how to 'untrigger' the gui. cuz it just stays there thruout the game now.

May 10 '10 at 05:05 AM ZeNooB

just set showgui to false in OnTriggerExit

May 10 '10 at 05:16 AM Mike 3

Don't forget to accept the answer :)

May 10 '10 at 07:21 AM Random Indie
(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:

x3812
x3419
x1060

asked: May 10 '10 at 04:22 AM

Seen: 1578 times

Last Updated: May 10 '10 at 04:44 AM