using trigger collider and animation to open door

im have a bit of a problem, i’m trying to open a door with collider and using a animation clip to open and close the door.
-heres the code i have so far-

function OnTriggerEnter (other: Collider){
animation. play(“dooropen”);
Debug. log (“you hit the collider”);
}

function OnTriggerClose (other: Collider){
animation. play(“doorclose”);
Debug. log (“you exit the collider”);

}

what am i missing… please help

yea i tried that but still not working…

Did you assign the animations in the inspector? What level is the script and what level is the animation? If the animation is on the door which is a child of the building and you attach the script to the building you will have to fetch it.

2 Answers

2

That’s OnTriggerExit

Check which layers each collider is on, and check your physics layer settings
(Edit → Project Settings → Physics → Layer Collision Matrix.

Also be sure that during runtime: the collider’s game object is active, the collider component itself is enabled, and the script is enabled.

Also, only objects with a collider or a rigid body can trigger other colliders.