Invoke method is not called
void Awake ()
{
Invoke("Explode",2.5f);
}
IEnumerator Explode ()
{
// stuff...
// explosion is a ParticleSystem
yield return new WaitForSeconds(explosion.main.duration);
Destroy(gameObject);
}
void Update ()
{
Debug.Log( IsInvoking("Explode"));
}
I do not destroy my object before invoking, nor when it is invoking. The log in the update function affirms that it is invoking the method Explode for 2.5f, then it switch back to false. The object is a MonoBehaviour. It is instatiated on runtime. However I tried to load it through the editor and the same result happen: THE INVOKE CALL IS NOT CALLED. there is no error too. If I invoke "Explodes" instead of "Explode" the compiler understand that there is no function called that way. So the compiler sees the method "Explode"...
Thanks for your time. ;)
I think that didn't work because the string used in your Invoke() should be a method name rather than a coroutine name. It should work like this :
void Awake() { Invoke ("DoExplosion", 2.5f); } void DoExplosion() { StartCoroutine(Explode); }
Answer by Andrea_Marchetti · May 25, 2017 at 12:27 PM
I "resolved" by calling StartCoroutine instead of Invoke, and then WaitingForSeconds at the beginning of the method called. I still have no idea why it didn't work.