- Home /
Question by
guitargodd97 · Jun 27, 2012 at 01:50 AM ·
freezelevelendgamecomplete
End of Level Freeze
So, I have a code that when a certain number of crystals are collected, a gui button pops up, that when clicked takes you to the next level. What can I add to my script that makes it so that when the button pops up, the player can not move and the enemies no longer attack you. So, is there like a pause control script or anything ?
[EDIT]
Okay, so I added a part to it and when it loads the next level it is still frozen. Here is what I have:
var message: Texture2D;
var button: Texture2D;
var nCrystals = 0;
var neededCrystals = 10;
var nextLevel = 0;
function OnGUI()
{
if (nCrystals >= neededCrystals)
{
savedTimeScale = Time.timeScale;
Time.timeScale = 0;
GUI.DrawTexture(Rect((Screen.width-message.width)/2, 200, message.width, message.height), message);
if (GUI.Button(Rect((Screen.width-button.width)/2, 400, button.width, button.height), button))
{
Application.LoadLevel(nextLevel);
Time.timeScale = 1.1;
}
}
}
Comment
Answer by Berenger · Jun 27, 2012 at 02:06 AM
http://lmgtfy.com/?q=Unity3d+pause+game
[EDIT]
I don't think Unity finish the frame after LoadLevel. You should restore the timeScale before calling it. And use savedTimeScale instead of 1.1.