判断游戏是否失去焦点,暂停游戏
using UnityEngine;
public class TestFocus : MonoBehaviour {

    bool isPaused = true;

    void OnApplicationFocus(bool hasFocus)
    {
        isPaused = !hasFocus;
    }

    void OnApplicationPause(bool pauseStatus)
    {
        isPaused = pauseStatus;
    }
}


得到焦点(就是其他应用切换回来的时候),先调用Pause(false)再Focus(true)

失去焦点(切换到其他应用),先调用Focus(false)再Pause(true)

Android弹出键盘,会调用Focus(false);Home键不会调用Focus(false),但是会调用Pause(true)


首页 我的博客
粤ICP备17103704号