- Home /
The question is answered, right answer was accepted
Crash the entire game
i want to know how to crash my entire game in case of failed loading of resources ? and how to personalize message or message box for it ? thank you
Do you mean something like...
Sprite s = null;
void StartUp()
{
LoadResources();
CheckForFail();
}
void LoadResources()
{
s = Resources.Load("sprite") as Sprite;
}
void CheckForFail()
{
if (s == null)
{
Debug.LogError("Loading failed! Quitting game!"); // Change to GUI so the player can see it
Application.Quit;
}
}
?
i don't want to do that for every texture or resource, i want a global game crush but thanks anyway, this can helpful in some case
Answer by markzpot · Jul 15, 2014 at 06:23 PM
This will quit the application:
Application.Quit;
http://docs.unity3d.com/ScriptReference/Application.Quit.html
ok that's what i look for, a global crush of my game when a loading of any resources is failed textures,hardwares etc... thank you guys will hit +1 :)
Answer by Firedan1176 · Jul 15, 2014 at 06:40 PM
Another solution that is not documented is using:
Application.Suicide(1);
Keep in mind this should NOT be used in the editor unless you saved your project. If you're curious, it just makes Unity crashes and warns Windows that it "crashed". The Unity Error Report window also pops up.
Answer by Kiwasi · Jul 15, 2014 at 06:42 PM
You could always throw an exception. This will work in the editor, and will behave very similar to any other error during GamePlay.
Follow this Question
Related Questions
Unity Editor Crashes On Play Because of Import Script 1 Answer
Unity Crashes Every time I Try To Run This Code 1 Answer
Victory menu is not working HELP 1 Answer
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer