Reputation: 19956
before load oher scene,i have many task to run ,for example save some date to sql and so on,i run the task at coroutine.As you know when call SceneManager.LoadScene,the ondestory is call,so my questions are:
Upvotes: 0
Views: 425
Reputation: 7417
You should call Object.DontDestroyOnLoad in the Awake method of your MonoBehaviour where your coroutine task runs, like described on Unity documentation:
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
void Awake() {
DontDestroyOnLoad(transform.gameObject);
}
}
This code will allow your coroutine ends even if another level was loaded.
Upvotes: 1