Loading an animation OnCollision

I have created a scene that requires a door to be opened to proceed, the door is controlled by an animation and I want the animation to play when the character enters the pressure pad which in this case is simply a cube. Here is what I have so far, I no it won’t load the animation for the door when the cube is collided with, that is were my problem is.

using UnityEngine;
using System.Collections;

public class OpenDoor : MonoBehaviour {

void OnCollisionEnter (Collision Collision)
{
if(Collision.gameObject.name == “player”)
{
animation.Play(“DoorClose”);
}
}

}

Drop this on your trigger object (make sure IsTrigger is checked on your collision object). Then drag the animation script from your door into the Door variable slot on the script. Then when your player walks into the trigger, the animation on the Door object will play “DoorClose”

using UnityEngine;
using System.Collections;

public class OpenDoor : MonoBehaviour
{
	public Animation Door;
	
	void OnTriggerEnter(Collider other)
	{
		if(other.gameObject.name == "player")
		{
			Door.Play("DoorClose"); 
		}
	}
}

I’d also advise against checking the object by name. Set it on it’s own layer and check gameObject.layer or something similar to that.

When assigning the script to the trigger, I can’t assign a variable animation? it just doesn’t work.

You need to drag the Animation script that is on your Door object into the Door variable on your trigger.