LoginSignup
30

More than 5 years have passed since last update.

Unityバックグラウンドでの処理 & 動作の検出

Posted at

バックグラウンドでの処理

  • 非Active時にUnityの動作を続けるように設定する

File > BuildSettings > Player Settings

を選択し、Run In Backgroundにチェックを入れる

Main_unity_-_DynamicPatch_-_PC__Mac___Linux_Standalone__Personal___OpenGL_4_1_.png

バックグラウンドへの移行と復帰を検知する

OnApplicationPause(bool pause)を使い、引数pauseStatusでバックグラウンドへの移行とフォアグラウンドへの復帰を判別します。

hoge.cs
    void OnApplicationPause (bool pauseStatus)
    {
        if (pauseStatus) {
            Debug.Log("applicationWillResignActive or onPause");
        } else {
            Debug.Log("applicationDidBecomeActive or onResume");
        }
    }

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30