I have a looping sound of my character swimming/pushing a boulder our sfx designer done the sounds and sent us the BANK, everything is working great but I can’t get my head around how to handle 3D looping sounds.
Reading the StudioEventEmitter I ended up with this code
if (_rigidbody.velocity.magnitude > 0.1f)
{
if (!isPlayingLoopSound)
{
loopSoundInstance = FMODUnity.RuntimeManager.CreateInstance(waterSwimSound);
loopSoundInstance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));
FMODUnity.RuntimeManager.AttachInstanceToGameObject(loopSoundInstance, transform);
loopSoundInstance.start();
}
}
else
{
if (isPlayingLoopSound)
{
loopSoundInstance.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
loopSoundInstance.release();
}
}
Except that the sound is not fading on stop this code is working but I feel like I’m not doing it in the right way, I don’t want to create a new instance everytime the character move again and don’t think I should release it everytime character stop while swimming.
Can someone give me an hint about how to handle looping sound playback?