How to use c# to call animations

How do I get my script to say that once I enter a trigger, the door opens. I have been at this for over an hour with no real progress. Please help.

C#

using UnityEngine;
using System.Collections;

public class Door_OpenScript : MonoBehaviour {

	public GameObject door;
	public AnimationClip anim;

	void Start(){

		door = GameObject.Find ("Door_Sliding");
		anim = GetComponent ("Animation");

	}


	void OnTriggerEnter(Collider Other){

		Animation.Play ();

	}
	
}

Firstly you should correct your code as said by @DiegoSLTS.

Other thing is you need to mark your animation as legacy. For this use the following steps:

  • Select your animation in Project window
  • Then in Inspector window select debug mode by write click on the icon next to lock icon.
    53377-screen-shot-2015-09-03-at-43956-pm.png
  • Then set animation type to 1 (legacy type)
    53378-screen-shot-2015-09-03-at-44314-pm.png

Hope this helps

Does your code compile? Your defining the “anim” variable of type “AnimationClip” and assign an Object to it with “GetComponent(“Animation”)”. Also “Animation.Play” means “call the static method Play on the Animation class”, but Animation.Play is not static, you need an Animation instance.

I think this should work:

 using UnityEngine;
 using System.Collections;
 
 public class Door_OpenScript : MonoBehaviour {
 
     public GameObject door;
     public Animation anim;
 
     void Start(){
 
         door = GameObject.Find ("Door_Sliding"); //not sure why you have this, it's never used
         anim = GetComponent<Animation> ();
 
     }
 
 
     void OnTriggerEnter(Collider Other){
 
         anim.Play ("YourAnimationClipName"); // <--- Change this to the actual name of the animation
 
     }
     
 }

@431studios Try this:
Get a reference to the Animator component and play the animation in the state machine.
eg:

using UnityEngine;

public Animator AnimRefObj;

    void Start()
    {
    AnimRefObj=GetComponent<Animator>();
    }
    void OnTriggerEnter(Collider Other)
    { 
    AnimRefObj.Play("door_slide_in");   //use the name of your animation clip in the quotes.
    }

static Animator anim;

void Start () {		
    anim = GetComponent < Animator>();	

}

void Update () {
         anim.SetBool ("Iswalking", true);
}