In Unity:
Scene A:
A loop sound event “music” is playing at start up (Event Emitter - Object Start).
Scene B:
The same loop sound event “music” is playing at start up (Event Emitter - Object Start).
If I switch from Scene A to Scene B:
I want to prevent the “music” sound event in Scene B to be played as it is already playing from Scene A.
But, if I switch from Scene C (no such sound) to Scene B:
I want to play the “music” sound event.
Any thoughts ?
Attempt:
I tried to detect if the the music instance is playing (c.f. below).
The method is working, but only while staying in Scene A.
The moment I switch to Scene B, I no longer get the state of the instance.
public class AudioInstance : MonoBehaviour
{[SerializeField]
private FMODUnity.StudioEventEmitter emitter;public static bool IsPlaying(FMOD.Studio.EventInstance instance)
{
FMOD.Studio.PLAYBACK_STATE state;
instance.getPlaybackState(out state);
return state != FMOD.Studio.PLAYBACK_STATE.STOPPED;
}void Update() { if (emitter.IsPlaying()) { Debug.Log("Emitter is playing"); } else if (!emitter.IsPlaying()) { Debug.Log("Emitter is not playing"); } }
}