Dear,
I’m having trouble stopping the sound instances using OnDestroy() when transitioning from the level scene to the main scene. Interestingly, it works fine when transitioning from the main scene to the level scene. Although the OnDestroy() function is executed, the stop and release commands don’t seem to work for some unknown reason. Could someone please take a look at my code and provide some guidance?
void Update(){
PlayAirWind();
PlayVehicleSound();
}
void OnDestroy(){ // transit to other scense need to remove the instance that created on Start()
wind.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
wind.release();
vehicle.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
vehicle.release();
// enemyZone.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
// enemyZone.release();
}
void PlayAirWind(){
FMOD.Studio.PLAYBACK_STATE fallState;
wind.getPlaybackState(out fallState);
if (!playerController.isOnGround){
wind.setParameterByName("Height", playerController.relativeHeight);
if (fallState != FMOD.Studio.PLAYBACK_STATE.PLAYING){
wind.start();
}
}
if (playerController.isOnGround || playerController.moveSpeed == 0){
wind.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
}
}
void PlayVehicleSound(){
FMOD.Studio.PLAYBACK_STATE vehicleState;
vehicle.getPlaybackState(out vehicleState);
if (playerController.vehicleOn){
vehicle.setParameterByName("Height", 20);
if (vehicleState != FMOD.Studio.PLAYBACK_STATE.PLAYING){
vehicle.start();
}
} else {
vehicle.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
}
}
I do not know where I did wrong. Thanks.