I was trying to create a trigger zone so that when you pass into a sphere collider with Is Trigger checked, the music starts, and when you exit the music stops. There's only one problem. If I actually start inside of the sphere collider, and take a step forward, the audio that was already on by 'play on awake' stops for a second and the audio restarts. I'm guessing that once I move the OnTriggerEnter Function is called and so it restarts. What way could I could start with the player inside the sphere without the audio restarting once I move?
#pragma strict
private var theCollider: String;
function OnTriggerEnter (other : Collider)
{
theCollider = other.tag;
if(theCollider == "Player")
{
audio.Play();
audio.loop = true;
}
}
function OnTriggerExit (other : Collider)
{
theCollider = other.tag;
if(theCollider == "Player")
{
audio.Stop();
audio.loop = false;
}
}