How can i disable a specific box collider of an object when i click a key in keyboard ??

How can i disable a specific box collider of an object when i click a key in keyboard ??

I’m not sure if this is old and they finally updated the Collider but you can disable or enable a collider from code pretty easily, it’s the collider.enabled bool:

if(Input.GetKey(KeyCode.E))
{
    collider.enabled = true;
}

I am using Unity 4 but I thought I saw this in 3.5 a while ago. I see some comments talking about it in duck’s answer, saying colliders don’t have an enabled bool but I just tested it and it works just fine

You can change your collider's "isTrigger" variable to true, to change it into a trigger volume instead of a solid collider. This has the effect of disabling it - in that it won't cause other objects to stop or rebound if they hit it.

For example:

function Update() {
    if (Input.GetKeyDown(KeyCode.X)) {
        collider.isTrigger = true;
    }
}

(this will disable the collider of the gameobject on which this script is placed)

As enabling/disabling box colliders doesn't seem to be possible, instead try just scaling the collider to 0,0,0 when you wish to disable it and then back up to it's original size when you want to enable it. Job done.

var myOldSize:Vector3;

function DisableBoxCollider(myCollider:BoxCollider)
{
    //actually just resizes it
    myOldSize=myCollider.size;
    myCollider.size=Vector3(0,0,0);
}
function EnableBoxCollider(myCollider:BoxCollider)
{
    if(myOldSize!=Vector3(0,0,0))
    myCollider.size=myOldSize;
}

both “collider.isTrigger = true;” and “collider.enabled = true;” are correct, but in unity 5 you need to use GetComponent().enabled = false;

@Grimmy

Just declare a private variable above with the collider you’re using on the same game object,
Example: PolygonCollider2D polyCol;

Then assign it to its component in the start function,
Example: polyCol = GetComponent< PolygonCollider2D > ();

And now you can use that variable to enable/ disable the collider or even set isTrigger to true or false.