Did you try changing it in the editor? go to Edit -> Project Settings -> Player. The inspector pane will now change to show the player settings. Look for the option that says "Run In Background" and uncheck it. From what I understand Application.runInBackground == false
more of pauses it than stops the script from running. If your project is for mobile(or maybe just add this anyway, it might help),try:
RuninBackgorund is ignored for Android and IOS how you can see here
The only and efficient way to run in background on Android is through a Service. You can use OnApplicationPause method to get notified when the game pauses/unpauses.
public void OnApplicationPause(bool paused) {
if(paused) {
// Game is paused, stop service notifications.
} else {
// Game is unpaused, start service to get notifications
}
Here you have a nice tutorial about communication between android and unity
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…