So currently I have an audio clip that is 8 seconds long. However I want to be able to stop it from playing when specific things happen. Something like this:
private AudioSource soundPlayer2D;
private AudioClip sound;
void Start(){
GameObject new2DsoundPlayer = new GameObject ("2DSoundPlayer");
soundPlayer2D = new2DsoundPlayer.AddComponent<AudioSource> ();
new2DsoundPlayer.transform.parent = transform;
}
void Update() {
if(shouldPlayAudio){
soundPlayer2D.PlayOneShot (sound, fxVolumePercentage * allVolumePercentage);
} else if(shouldStopAudio){
//Stop Audio <--
}
}
Edit 1: Note I only want to stop the specific audio clip and not the Audio Source