- Home /
Invoke not working
I have made a button which when I click it, it destroys certain game objects, everything works perfectly, except the invoke method, it just doesn't work. It doesn't return an error, it just doesn't even call the function. Maybe someone can help me figure this out?
     void OnMouseDown()
     {
         if(startButton == true)
         {
             startButton = false;
             anim = (GameObject)Instantiate(anim,new Vector3(0, 0,v3.z),transform.rotation);
             anim.transform.parent = parent;
             Destroy(destroyBg);
             Destroy (gameObject);
             Destroy(destroyAnim, time);
             generator.Generate();
             Invoke ("GuiCreate", 2);
         }
     }
 
     void GuiCreate()
     {
         guiMain = (GameObject)Instantiate(guiMain,new Vector3(0, 0,v3.z),transform.rotation);
         Debug.Log("CreateGUI was called");
     }
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Simon-Larsen · Apr 08, 2014 at 12:37 AM
Make sure you don't Destroy the gameObject before the invoke method has actually Fired
 void OnDestroy () {
     Debug.Log ("I was killed? :(");
 }
Edit: The Invoke method still works if the gameObject is just disabled, use that to your advantage.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                