- Home /
Not Formatted
Audio help.
I Need help with an script in an audio of me. When im touching the brick the audio will play but i need to insert a line of script so that when i have touched the brick the sound cant be player again. : ' #pragma strict
var loudBang:AudioClip;
function OnTriggerExit(o:Collider){ Debug.Log("The trigger fired");
audio.PlayOneShot(loudBang);
}
This is JS. Where do i put the line of script so that when i touch it it cant be played again.
MORE INFO ( If necesarry ) :
Its a gameobject Its a audio source I did the script in JS
Thanks
Vince
YOU $$anonymous$$JST FOR$$anonymous$$AT CODE IN QUESTIONS.
Thanks for replying, by checking the audio loop it will stil play when i have touched it right? Because i need it to play one time and then just destroy the Item so that it isn't able to make the sound again.
Vince
YOU $$anonymous$$JST FOR$$anonymous$$AT CODE IN QUESTIONS.
Answer by SubatomicHero · May 09, 2013 at 12:52 PM
I would suggest using booleans to control your music playing:
// at the top with loudbang
var loudBang : AudioClip;
var touchedWall : boolean = false;
// then in your OnTriggerExit() function
function OnTriggerExit(col : Collider)
{
Debug.Log("The trigger fired");
if (!touchedWall) // if touchedWall is false
{
touchedWall = true;
audio.PlayOneShot(loudBang);
}
}
// maybe in your OnTriggerEnter() function you should add
function OnTriggerEnter(col : Collider)
{
touchedwall = false;
}
or you could simply check first to make sure that the audio looping box is unticked in the inspector