- Home /
Deactivating an object on getbutton
I want to deactivate a child object when a button is pressed but i have no idea how to do this, i got this code where i want to implement it: The object i like to deactivate is an object called idle.
if (Input.GetButtonDown("Jump")) { var objjump = Instantiate(jump, transform.position, transform.rotation); objjump.transform.parent=transform;
//yield WaitForSeconds (5);
}
EDIT: If possible i also like to know how to activate it again later..
Answer by FLASHDENMARK · Feb 15, 2011 at 07:31 PM
renderer.enabled = false; // When you want to deactivate it.
renderer.enabled = true; // When you want to activeate it again.
Yes. When one statement is true, then use one of the code form above you want to use for the specific job.
Any questions just ask! :)
Answer by Persona · Feb 15, 2011 at 07:27 PM
objjump.active = false;
Also you should set a boolean to check if it's off or on, so when you press it again, it will activate.
yea adding a boolean won't work since there is a transform in the variable
What I mean is add a boolean like:
if(Activate){ objjump.active = false; }
Your answer
![](https://koobas.hobune.stream/wayback/20220613104547im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to deactivate background music when I land on an object? 1 Answer
How to deactivate objects that are children all at once? 0 Answers
How to find world coordinates within an object? 1 Answer
Enemy Problem 1 Answer
Look at Object 1 Answer