- Home /
Triggering door animation with collider
I have a door with animations and a empty game object separate to this which has a box collider with trigger marked, I've been looking everywhere for some script to make the door open when the character enters the trigger box collider. I've been searching everywhere for a script to add to the game object and one to add to the door to make them work but i've had no luck and I feel like i've tried everything. Does anyone had a script I can try. It would really help me out.
Thanks
James
Answer by PaulBrasfield · May 03, 2013 at 10:41 PM
Try this:
function OnTriggerEnter(other : Colldier) {
animation.Play("YourAnimationHere");
}
I assume this is what you need.
I have no script on either the door or the collider.
The door that holds the animation is a child to the game object collider.
$$anonymous$$aybe i need to re arrange things or even create new objects, could really use some help, as you can probably tell I'm quite new to unity.
If you want the animation on the door to play, you'll need a script.
Answer by oliver_ · May 04, 2013 at 03:22 AM
The script above would work. However, it would be best if the trigger was directly assigned to the door. ie not having the trigger on a separate object. Having a script assigned to the empty would apply the actions to the empty (not giving the desired result), likewise having it on the door would not do anything as the door itself does not have the trigger required. Give the door another box collider set as a trigger, and assign the script to the door, delete the empty.