- Home /
Question by
AppleJuicy · Jan 27, 2015 at 03:58 PM ·
triggercolliders
How to Disable/Enable other GameObject Collider2D
public GameObject other;
void OnTriggerStay2D (Collider2D col) {
if (col.gameObject.tag == "Player" )
{
other.collider2D.enabled=false; // <--- this doesnt work
}
}
}
i wanted gameobject other to disable collider when enter trigger, enable collider when exit trigger. do i need to use GetComponent method? i am not sure how to use it though.
please help thankx.
Comment
Answer by Taxen0 · Jan 27, 2015 at 05:17 PM
That is correct, use
other.GetComponent<Collider2D>().enabled = false;
Or...Change the public variable other to a Collider2D instead of GameObject and simply use other.enabled = false; If you don't need to use it elsewhere in the code =)
Answer by unity_kSh6Vq9W3pUseg · Jun 04, 2018 at 09:47 PM
what if we cant to make it true in the same collider? how are we going to do that, because once we make it false we cannot come again in the collider?