- Home /
Turn Off Capsule Collider via JavaScript
Hello Guys! I'm new to unity, and I'm having a problem! I want to turn off the Capsule Collider from a GameObject via JavaScript, wait a few seconds and turn it on again, but i don't know how to turn it on or off... can you guys help me?
#pragma strict
function Start () {
}
function Update ()
{}
function OnCollisionEnter(hit : Collision)
{
if(hit.gameObject.tag == "ClimbHighTrigger")
moverparaheroi.colisao = 0;
********TURN OFF CAPSULE COLLIDER HERE******
yield WaitForSeconds (3);
myComponent = true;
********TURN ON CAPSULE COLLIDER HERE*******
moverparaheroi.colisao = 1;
}
Answer by aldonaletto · Oct 06, 2013 at 10:36 PM
You could set/clear collider.enabled :
function OnCollisionEnter(hit : Collision)
{
if(hit.gameObject.tag == "ClimbHighTrigger"){
moverparaheroi.colisao = 0;
collider.enabled = false;
yield WaitForSeconds (3);
myComponent = true;
collider.enabled = true;
moverparaheroi.colisao = 1;
}
}
But if you want a trigger, just check its Is Trigger checkbox.
NOTE: This code turns on/off the collider of the object it's attached to. If you want to disable the other object's collider, use hit.collider.enabled instead.
Answer by Gaban · Oct 06, 2013 at 10:47 PM
You could try setting it to trigger, with this:
gameObject.collider.isTrigger = true;
instead of moverparaheroi.colisao = 0;
Your answer
![](https://koobas.hobune.stream/wayback/20220613115435im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
OnCollisionEnter2D not working? 2 Answers
Setting Scroll View Width GUILayout 1 Answer
Enable objects to enter the trigger 2 Answers
Go kinematic when in collider 1 Answer
Playing Different Animation Troubles 0 Answers