- Home /
 
               Question by 
               Jammer3000 · Dec 08, 2013 at 12:34 AM · 
                activatedeactivate  
              
 
              How to activate and deactivate a gameObject
Hi I have a project where I want to deactivate a gameObject when I click the "m" key and reactivate it when I click it again, but the code I'm using makes perfect sense but for some reason won't activate the gameObject once its deactivated.
Here's the code I'm using:
 function Update () {
     
     if(Input.GetKey("n")) {
     // Deactivates the game object.
     gameObject.SetActive (false);
 
     }
 
     if(Input.GetKey("n") && gameObject.SetActive == false) {
         Debug.Log("fire");
     gameObject.SetActive (true);
 
     }
     
 }
               Comment
              
 
               
              Answer by Eric5h5 · Dec 08, 2013 at 12:36 AM
Well, once you deactivate it, naturally the code won't work after that. You can activate/deactivate it it from another script (which stays active). Another possibility is to disable the renderer, in case you're just trying to deactivate that and not the entire object.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                