I have a game object where i want to play a song only when the player is within a collider, but i dont want it to stop happening everytime i enter it again. I have this so far, but it still stops…
using UnityEngine;
using System.Collections;
public class SoundTrigger : MonoBehaviour {
public AudioSource source;
public AudioClip clip;
private bool isPlayed;
public void Awake ()
{
source = GetComponent<AudioSource>();
isPlayed = false;
}
public void OnTriggerEnter(Collider other) {
if (!isPlayed)
{
source.Play();
isPlayed = true;
}
}
public void OnTriggerExit(Collider other)
{
if (source.isPlaying)
{
source.Stop();
}
}
}