I’ve been looking into this and just can’t seem to figure out what I’m doing wrong. I want an invokerepeating to cancel when the gameObject is inactive. Here’s what I’ve got:

void Start()
{
    if (gameObject.activeInHierarchy==true)
        InvokeRepeating("TheGust", starttime, delaytime);
    else
        CancelInvoke("TheGust");

}

Do I need to put the cancelinvoke in the update function and, if so, how?

Many Thanks

void OnEnable()
{
InvokeRepeating(“TheGust”, starttime, delaytime);
}

void OnDisable()
{
     CancelInvoke("TheGust");
}