- Home /
How to know when my game is in background?
Hi guys,
I'm working in an iOS game with Unity and I need to know when the player has pressed the Home button a.k.a when the game just entered background.
A little research show me that I may need to use OnApplicationPause and/or OnApplicationFocus. Do you guys know what this is?
The reason is because a schedule local notification I want create ONLY when the player has the game in background.
Thanks!
Answer by dannyskim · Oct 08, 2012 at 11:15 PM
OnApplicationFocus is what you're going to want to use, which works on all supported platforms I believe.
OnApplicationFocus() is a override-able method, meaning that Unity has left the implementation of this method up to you, such as
void Start()
or
void Awake()
So, in your script you would do:
void OnApplicationFocus( bool focus )
{
if( focus )
{
// Put your scheduled local notification here
}
}
Your answer
Follow this Question
Related Questions
Run a script in background when the app is open or closed 5 Answers
iOS Turn Off Push Notifications Pop Up 0 Answers
LocalNotifications deprecated in Unity 5 2 Answers
Iphone build game size is too big! 0 Answers
Command line builds for iOS - pro only? 0 Answers