Pause questions

From the Unity manual:

bool UnityPause(int pause)

“Pauses Unity if you pass 1, unpauses if you pass 0, useful if you want to temporary freeze your game, for ex., when your game is snapped.”

  1. What is the return value used for? I always get a return value of false, no matter what the input, or whether or not it works.

  2. When the user switches away from my game, I would like it to pause (it does), but I’d like it to remain paused when I return (it doesn’t) until the user indicates that they are ready. So far, nothing I’ve tried will get the game to stay (or immediately return to) paused when the app switches back, it always automatically comes out of being paused. I’ve tried doing nothing at all, not requesting unpause on return, explicitly requesting pause in a visibility changed handler… my code to pause (which works if the user clicks the button) is being called, but the game is not pausing.

I’ve written a small test example, in case it was something else in the game that was causing it to resume, but that test project behaves the same way. Has anyone successfully maintained a paused state on returning to the app? What did you need to do?

Did you look at the Unity - Scripting API: MonoBehaviour.OnApplicationFocus(bool) ?

Can that help me override the default behaviour of Unity, or is that only for writing my own Pause state in addition to Unity’s? Thanks!

Well, in either case, you have to somewhere state - that now you’re showing a pause menu. And this would the place where you would enable it.

Actually, the button is XAML and the code is in the Visual Studio side of the project. I call UnityPlayer.AppCallbacks.Instance.UnityPause( 1 ); from my MainPage.xaml.cs, and throw up a XAML pause screen. I take it this isn’t how you expected us to do things? Do any of the posted examples have a pause I can look at? I was looking at the Windows Store porting document (pg 18-19) at http://unity3d.com/pages/windows/porting, and an example UnityPorting\PlatformerApps\PlatformerWindowsStore\Platformer.sln, which I think I got from https://github.com/windowsgamessamples.

I would say no, because that means your pause menu will be available only on Windows Store Apps, it makes more sense to make a pause menu inside Unity project, you would then be able to use that menu on other platforms as well.