Question by 
               theunsigned · Feb 01, 2019 at 01:33 PM · 
                invokeinvokerepeatingcancelinvoke  
              
 
              why won't an invokerepeating cancel?
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
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Hellium · Feb 01, 2019 at 01:37 PM
  void OnEnable()
  {
      InvokeRepeating("TheGust", starttime, delaytime);
  }
 
 void OnDisable()
 {
      CancelInvoke("TheGust");
 }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                