Pretty straight forward question with apparently no answer online. The only answer I have seen is to alt tab out of Unity but that does not work. Any help is appreciated.
Works all day long. All you need is to click off the game window, on Unity or anything. You probably don’t have the script you think running.
using UnityEngine;
// @kurtdekker - drop this on a GameObject to report focus changes
public class oaf : MonoBehaviour
{
void OnApplicationFocus( bool focus)
{
Debug.Log( "oaf:" + focus);
}
}
If that doesn’t work then maybe you’re using a newer version of Unity that has some brand-new crazy player setting to turn this off but I suspect not.
For me I have:
Switch(focus)
{
case true:
Debug.Log(something);
break;
case false:
Debug.Log(Something else);
break;
}
and only the case true code runs. No matter what I do, alt-tab or click out of play window.
I think I figured out the problem. I was using the device simulator to run the game. when I switched to game view, the code ran. Must be a bug with device simulator.
The Device Simulator still doesn’t get “lost focus” events when clicking outside the simulator view.
Is there a different way to simulate “lost focus” in the device simulator?