- Home /
How to Make the Game Go to the Next Level When the Music Stops
I am trying to make a intro to a Sonic.exe like game I'm working on, but I dont know how to make the game go to the next scene when the music stops, if you guys can help me, It would be great! BTW: I don't have unity Pro -_-
Hello
You need a flag to time the end of the audioclip
something like this :
public AudioClip introClip;
void Start () {
audio.clip = introClip;
audio.Play();
StartCoroutine("IntroEnding");
}
IEnumerator IntroEnding(){
yield return new WaitForSeconds(introClip.length);
Application.LoadLevel("...");
}
cheers
Answer by ahgr123 · Jul 08, 2014 at 05:03 PM
Look in the application class, it offers some scene loading functions:
http://unity3d.com/support/documentation/ScriptReference/Application.html
for example Application.LoadLevel();
http://unity3d.com/support/documentation/ScriptReference/Application.LoadLevel.html
Answer by JusticeAShearing · Jul 08, 2014 at 05:05 PM
I have two ways that could help you. It is one, or the other, due to whichever circumstances arise.
First One:
This depends on the idea that you have a script which activates the sound. If that is so, apply this code to the script. I do hope that it works for you. If it doesn't, or you would like the gaps filled in, please post the full script that activates the sound.
This script is written in Java-Script. If you want it in another language, tell me and I will try to translate it.
//This code is applied at the end
function OnMusicStop ()
{
Application.LoadLevel("the level that you want to load")
}
//This code is applied within the function that plays the music, so that when the music stops, this occurs
OnMusicStop();
If there is no script, please further explain the specific circumstances.
Please post your script if there is one, so I can give it to you with my additions in it.
Replace 'the level that you want to load' with the number assigned to the level that you want to load. This is found by entering the exportation menu, when it lists the levels, they have numbers next to them. This defines what number that the level is. For instance, FullWorld could be its name, but 5 could be its number.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
how to switch between scene 4 Answers
how to change a script property for multiple objects 1 Answer
Audio Clip trouble 2 Answers
GUIlayout background image or color 0 Answers