- Home /
Restart sound when re-entering trigger?
Hey! So as it says I have a very simple script for playing a sound via collider trigger. However, when you enter the trigger zone again, the sound doesn't restart, it plays again but over the already playing sound. I want some way for it to stop its previous playing and restart?
Here is the script: public class SoundTrigger : MonoBehaviour {
     void OnTriggerEnter(Collider coll)
     {
         if(coll.gameObject.tag == "Player")
             audio.PlayOneShot(audio.clip, 1.0f);
     }
 }
Disclaimer I am an art student and not very proficient in coding.
Answer by AngryBurritoCoder · Nov 15, 2014 at 12:16 AM
just add another method of:
 void OnTriggerExit(Collider coll)
 {
     if(coll.gameObject.tag == "Player")
     {
          audio.Stop(your clip);
     }
 }
CANT REMEMBER PROPER METHOD , but this should be close, made it on the fly and quite tired
Your answer
 
 
             Follow this Question
Related Questions
Repeat While Object in Range 1 Answer
Not able to set explosion.SetActive(true) on player destroy 1 Answer
Script works for NPCs, but not Player 1 Answer
Need help making an audio trigger. 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                