- Home /
Need Help making my game return to Main Menu after a level ends
Hello, In My Game (IPhone Game) I have ten different levels. I have been trying to make it so after someone completes a level it loads the main menu, for this I was using a script from the "Penelope" Tutorial but it seemed to not be working.
I was Wondering if anyone had a better way of doing this or a way to fix this. Thanks.
Here is an example of the part of the script:
private function EndGame() { var animationController : AnimationController = GetComponent( AnimationController ); var prefab : GameObject = Instantiate(guiMessage); var endMessage : GUIText = prefab.GetComponent( GUIText );
if(carrying >= winScore)
{
//Player wins
endMessage.text = "You win, Cheese!";
PlayAudioClip( winSound, Vector3.zero, 1.0 );
animationController.animationTarget.Play( "WIN" );
}
else
{
//Player loses
endMessage.text = "No Cheese For You!";
PlayAudioClip( loseSound, Vector3.zero, 1.0 );
animationController.animationTarget.Play( "LOSE" );
}
// Alert other components on this GameObject that the game has ended
SendMessage( "OnEndGame" );
while( true )
{
// Wait for a touch before reloading the intro level
yield WaitForFixedUpdate();
if ( iPhoneInput.touchCount > 0 && iPhoneInput.GetTouch( 0 ).phase == iPhoneTouchPhase.Began )
break;
}
Application.LoadLevel( 0 );
}
Also here is the receiver to the "OnEndGame:
function OnEndGame() { // Disable joystick when the game ends moveJoystick.Disable(); rotateJoystick.Disable();
// Don't allow any more control changes when the game ends
this.enabled = false;
}
You can just add a GUI.Button that appears when the level ends and says "Done" and have it do the Application.LoadLevel
http://unity3d.com/support/documentation/ScriptReference/GUI.Button.html
Answer by AliAzin · Jul 22, 2010 at 07:17 AM
you can simply add this line at the end of OnEndGame() function :
Application.LoadLevel(0);// loads the first level of game
if your main menu is the first level.
Your answer
Follow this Question
Related Questions
Android Button Text 1 Answer
how to load random level but one? 3 Answers
how can i make a block menu 1 Answer
script to save and load a game 3 Answers
checkpoint level please 2 Answers