- Home /
Duplicate Question
I want my trigger sound only to play once!
I just wanted to start of saying that im not so good at scripting. I have this script that makes it so when gameobject, tag "Player" enters the trigger area, sound plays. Well when i enter the area it plays the sound but when i enter the area again the sound plays again and i want it to only be able to play once. Here is the script
var Sound : AudioClip;
function OnTriggerEnter(){
audio.PlayOneShot(Sound);
}
(javascript)
Answer by tone20 · Aug 16, 2013 at 05:11 PM
you can simply disable the trigger after you leave it
attach this to trigger
var myTrigger : GameObject; var myObject : GameObject;
function Start () {
myObject.SetActive(false);
}
function OnTriggerEnter () {
myObject.setActive(false);
}
function OnTriggerExit() {
myTrigger.SetActive(false);
myObject.SetActive(false);
}
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Play sound on mouse enter 1 Answer
How to make the trigger work only once. (SOUND) 1 Answer
Need a Timer Script 1 Answer
Audio help. 1 Answer