I have the following code:
void Start()
{
gameObject.SetActive(false);
StartCoroutine(Load());
}
IEnumerator Load()
{
yield return new WaitForSe
What I do to avoid stopping coroutine is have a game object that does not get deactivated.
public class CoroutineHandler : MonoBehaviour
{
private static CoroutineHandler instance = null;
public static CoroutineHandler Instance
{
get
{
if(instance == null)
{
GameObject inst = new GameObject("CoroutineHandler");
DontDestroyOnLoad(inst);
instance = inst.AddComponent();
}
return instance;
}
}
}
Then use this for such coroutines by using CoroutineHandler.Instance.StartCoroutine(RoutineMethodHere());.
If you do not want something like this, since it can go wrong or cause leaks if not handled correctly, you can try using Invoke("MethodName", delay);