Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在后台unity和pop通知中继续运行时间_C#_Android_Unity3d_Background Process - Fatal编程技术网

C# 在后台unity和pop通知中继续运行时间

C# 在后台unity和pop通知中继续运行时间,c#,android,unity3d,background-process,C#,Android,Unity3d,Background Process,我正在unity中开发一个游戏,我在其中加入了5分钟后玩家将获得1次生命的时间,我希望我的代码在玩家获得最大生命时弹出通知,即10次,甚至在游戏关闭时,因此我需要在后台运行时间。这是我创建的代码 void OnApplicationQuit(){ while(lifes < 10){ if (lifes < 10) { seconds -= Time.deltaTime; if (seconds

我正在unity中开发一个游戏,我在其中加入了5分钟后玩家将获得1次生命的时间,我希望我的代码在玩家获得最大生命时弹出通知,即10次,甚至在游戏关闭时,因此我需要在后台运行时间。这是我创建的代码

void OnApplicationQuit(){   
    while(lifes < 10){      
        if (lifes < 10) {
            seconds -= Time.deltaTime;
            if (seconds <= 0) {
               minutes -= 1;
               seconds  = 60; } 
            if (minutes < 0) {
               minutes = 4;
               lifes   += 1;
               PlayerPrefs.SetInt ("Lifes", lifes);
            }     
        }else{
             LocalNotification.SendNotification(1, 5, "Tilty Bob", "Your lifes are full play to unlock next", new Color32(0xff, 0x44, 0x44, 255));
             }
    }
}
void OnApplicationQuit(){
而(寿命<10){
如果(寿命<10){
秒-=Time.deltaTime;

据我所知,如果(秒),您希望您的应用程序在后台运行

但是OnApplicationQuit()只被调用一次:当你退出你的应用程序时。因此没有后台工作(检查API:“当用户停止播放模式时调用”)

您需要的是服务


祝你好运

我只需计算用户寿命达到最大值的时间,然后设置一个,不需要消耗电池。当然,如果玩家的寿命还没有满,那么在启动时运行一个逻辑来更新玩家的寿命。使用GCM也可以工作,但你的应用程序需要在线连接和服务器。