I found the answer to my question. Special thanks to Mr.Dinal24. With Mr.Dinal24, I can get my answer with an update of some things, and it is very useful for me.
NOTE: THIS WORK CODE FOR ANDROID AND IOS BOTH (FOR IOS SHOULD REQUIRE UNITS 4.6.1 OR ABOVE)
using UnityEngine; using UnityEngine.UI; using System.Collections; using System; public class Counter : MonoBehaviour { public Text counterText, pauseText, resumeText, msgText; private int counterValue, focusCounter, pauseCounter; private DateTime lastMinimize; private double minimizedSeconds; void OnApplicationPause (bool isGamePause) { if (isGamePause) { pauseCounter++; pauseText.text = "Paused : " + pauseCounter; GoToMinimize (); } } void OnApplicationFocus (bool isGameFocus) { if (isGameFocus) { focusCounter++; resumeText.text = "Focused : " + focusCounter; GoToMaximize (); } }
source share