- Home /
SetActive(true) dont work
Hi! Its code work, after collision game object deactivated
void OnTriggerEnter2D (Collider2D col) {
if (col.gameObject)
{
col.gameObject.SetActive(false);
}
}
but this code dont work, why?
void OnTriggerEnter2D (Collider2D col) {
if (col.gameObject)
{
col.gameObject.SetActive(true);
}
}
how to have it to activate game object?
Sorry for my English and thanks for your help
Answer by YoungDeveloper · Dec 29, 2014 at 09:35 PM
SetActive(false) disables the gameObject, which result in inactive update, ontrigger and all other update methods, so you will not be able to check anything from that gameobject updates such as collison and so on. This is a very old question and has been answered hundreds of times. Just do a quick google search and you will have tons of answers.
cheers
Tnx. I asked a question Google, but got no response, how to enable a game object after the collision.
I got it. I'm cant find a collision, if the gameobject is deactivated ...
Answer by AcE_fLoOdEr · Dec 29, 2014 at 10:15 PM
Here is how you do it:
GameObject object;
void Start()
{
// this will set an instance of the gameobject to your variable
object = GameObject.Find("Your object's name");
}
you can now use that GameObject variable to activate/deactivate at any time.
Your answer

Follow this Question
Related Questions
physics.OverlapSphere colliders 1 Answer
Alternatives to GameObject.SetActive(...) 2 Answers
Conflicting Box Colliders 0 Answers
C# iOS - .active, SetActive(false) 0 Answers
How do I alter all children of a gameobject at once? 1 Answer