I am trying to play sound clip immidiately before loading new scene.My sound clip does’t fully get played before i switch to new scene.what should i do??
i can’t use do not destroy on load.
I am trying to play sound clip immidiately before loading new scene.My sound clip does’t fully get played before i switch to new scene.what should i do??
i can’t use do not destroy on load.
Start playing the sound, and regularly check “yourAudioSource.isPlaying” to know when the sound has finished playing, then load the next scene.
EDIT:
You could also check the AudioClip’s length, start playing the sound, wait enough time, then load the next scene.
You can load your level using a co-routine where in you put the co-routine to execute after the time duration of your audio clip.
Check this Psuedo-code in c#:
In OnTriggerEnter():
if(player dies){
play audio;
StartCoroutine("LoadNewLevel");
}
In your Co-routine:
IEnumerator LoadNewLevel() {
yield return new WaitForSeconds(TheTimeOfYourAudioClip);
Application.LoadLevel("YourLevel");
}
Let us know the outcome.
Thanks everyone for your help. You helped me to track down the problem. Actually i was looking for rigidbody.constraints=RigidbodyConstraints.FreezeAll;
I actually needed a replacement for Time.TimeScale=0.
this is what i did:
using UnityEngine;
using System.Collections;
IEnumerator OnTriggerEnter( Collider _other )
{
if (_other.CompareTag ("w")) {
//Time.timeScale=0;
this.rigidbody.constraints=RigidbodyConstraints.FreezeAll;
_other.rigidbody.constraints=RigidbodyConstraints.FreezeAll;
this.GetComponent< AudioSource>().priority=0;
audio.PlayOneShot(wall);
time = Time.timeSinceLevelLoad;
yield return new WaitForSeconds(0.3f);
Application.LoadLevel("GameOver");
}
}