Hi guys , I want to share with you a ‘system for coroutines’/ interesting technique that will help you to stop wondering if the GameObject will be disabled . So if the game is paused (and main canvas will be disabled) the coroutine continue to work .
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using UnityEngine.Events;
/// <summary>
/// Instance used for coroutine on deactivated object
/// </summary>
public class ObjectEff : MonoBehaviour
{
public static ObjectEff instance;
void Awake()
{
MakeInstance();
}
public void MakeInstance()
{
instance = this;
}
/// <summary>
/// Execute a coroutine especially when your gameobject could be inactive
/// </summary>
/// <param name="coroutine">Make an instance of IEnumerator and send as a parameter for coroutine</param>
public void ExecuteCoroutine(IEnumerator coroutine)
{
StartCoroutine(coroutine);
}
}
Put this script on a single GameObject in the scene (also you can set DontDestroyOnLoad )
Basically you just have to call instead of StartCoroutine(coroutine) → ObjectEff.instance.ExecuteCoroutine(coroutine)
Good luck with using this system !