I am trying to make a door open when a First Person Player touches a button. This is the script in the button:
var Player : GameObject;
var door : GameObject;
function OnTriggerEnter (col : Collider) {
if (col == Player.collider){
door.animation.Play();
}
}
The animation is not played. The door does have an animation, the button does have a box collider that is set to a trigger, and the two variables are set correctly in the inspector. What is the problem?
In order for collisions/triggers to register, one of the colliding objects has to have a rigidbody component. Since I’m assuming you’re using a character controller for your player (or otherwise NOT using a rigidbody on it), and that adding a rigidbody would break the controls/gameplay you already ahve set up, I would recommend just adding a rigidbody to your button and they turning off “use gravity” and turning on “freeze rotation” and “is kinematic.” This will essentially make your object behave like a non-rigidbody object (it won’t move or rotate at all unless you specifially tell it to), but will allow it to handle collisions as though it were a rigidbody.
Also, this probably goes without saying, but your trigger object (the button for the door) needs to be set to be a trigger if you are going to use the OnTriggerEnter() function. This can be done by checking the box next to “Istrigger” in the collider component of your button.