Door Opener

I have a problem with my door opener script:

function Update () {
}

function OnControllerColliderHit(hit: ControllerColliderHit){
if(hit.gameObject.tag == “door1”){
Debug.Log(“hit”);
animation.Play(“doorOpen”);
}
}

Unity debugs the hit. But the animation doesn’t play. They door is a child of the parent “Lab” I place the animation clip in the “Lab” parent. Still whatever i do. The animation doesn’t play.

Instead of a collision detection do this

Put the script and animation on the door.
Make a box collider in front of the door where ever you want the player to trigger the door. Check the box that says trigger. Make sure the box collider is a part of the door.

change that code to this

function OpenDoor ()
{
	animation.Play("doorOpen");
}

Then change the door’s Tag to Door

then make a new script and attach it to your player and put this in it

function OnTriggerEnter (trigger : Collider) 
{
	 if (trigger.gameObject.CompareTag("Door"))
	 {
	 	trigger.gameObject.SendMessage("OpenDoor", SendMessageOptions.DontRequireReceiver);
	 }
}

Basically that will cause the player to trigger the code when he hits the box collider and send a message to the door to play it’s animation

Just make sure the door object is tagged Door and the box collider is part of the door object

Thanks, thats probably why the animation was not playing because the script didn’t tell the door to play the animation, it told the lab to play the door animation. THANKS!

var mydoor : GameObject;
mydoor.animation.Play("doorOpen");

If you can find the door object that you collided with, then that is a way of externally activating an animation.

Just a thought. :slight_smile: