- Home /
How can I disable a collider 3D when I trigger a collider?
You know how in Mine-Craft there is pressure plates and when you step on them they trigger something like open a door or something. Here's my thing. If my player is walking and trigger/touches a slightly different colored box on the ground and it's a trigger, can that trigger a box/cube on the ceiling to disable its collider and make enemies fall. Pretty much if I trigger something, can that then disable a collider on another gameobject. Thanks and i'll be as clear as possible. Thanks
public Collider colliderToDisable;
void OnTriggerEnter(Collider other) {
colliderToDisable.enabled = false;
}
You could also write a simple script "TriggerScript" (example name that holds a reference to the colliderToDisable, and attach it to the trigger gameobject, and then do it like this:
void OnTriggerEnter(Collider other) {
TriggerScript triggerScript = other.gameObject.GetComponent<TriggerScript>();
if(triggerScript != null) {
triggerScript.colliderToDisable.enabled = false;
}
}
So do I make a script, say I call it "DisableCollider", and add it to the object that I want to disable the collider? Then add the "TriggerScript" to the object that I want to be the trigger? By the TriggerScript I mean the second script that you posted, and the DisableCollider the first script you posted. Also would those scripts be in the Start or Update things or not?