Question about triggering an animation (Unity 5.0)

Hello,

This may be the simplest question but I can’t seem to trigger an animation using JS in Unity 5.0. All of the examples online are for deprecated code, and so don’t seem to work with this version of Unity. Here is the code…

function Update (){
    if(open){
    //Open door

    //play animation

    }
   
    else
    {
    //Close door

    //do nothing
   
    }

    if(Input.GetKeyDown("4") && enter)
    {
   
    open = !open;
   
    }
}

Now the animation is called openDoorNormal and is attached to the Animation component for the object, which is a door. I’ve tried the following…

door.GetComponent.<Animation>.Play("doorOpenNormal");

But it errors out. Actually now that I think about it, here is the full code…

private var open : boolean;
private var enter : boolean;
private var door : Transform;
 

//Main function
function Update (){
    if(open){
    //Open door

    door.GetComponent.<Animation>.Play("doorOpenNormal");

    }
   
    else
    {
    //Close door

    //do nothing
   
    }

    if(Input.GetKeyDown("4") && enter)
    {
   
    open = !open;
   
    }
}

//Activate the Main function when player is near the door
function OnTriggerEnter (other : Collider)
    {
   
    if (other.gameObject.tag == "Activate")
    {
   
    enter = true;
   
    }
    }

//Deactivate the Main function when player is go away from door
function OnTriggerExit (other : Collider)
    {
    if (other.gameObject.tag == "Activate")
    {
   
    enter = false;
   
    }
}

Thank you in advance for any suggestions…

Ok, so I think I found part of my problem. It looks like I was combining JS and C#… oops. Here is the C# version… still getting errors, but looks better…

// Converted from UnityScript to C# at http://www.M2H.nl/files/js_to_c.php - by Mike Hergaarden
// Do test the code! You usually need to change a few small bits.

using UnityEngine;
using System.Collections;

public class openDoorNormal : MonoBehaviour {
    private bool  open;
    private bool  enter;
    public Animation anim;
   
   
    //Main function
    void  Update (){
        if(open){

            anim.Play("openDoorNormal");
           
        }
       
        else
        {
            //Close door
           
            //do nothing
           
        }
       
        if(Input.GetKeyDown("4") && enter)
        {
           
            open = !open;
           
        }
    }
   
    //Activate the Main function when player is near the door
    void  OnTriggerEnter ( Collider other  ){
       
        if (other.gameObject.tag == "Activate")
        {
           
            enter = true;
           
        }
    }
   
    //Deactivate the Main function when player is go away from door
    void  OnTriggerExit ( Collider other  ){
        if (other.gameObject.tag == "Activate")
        {
           
            enter = false;
           
        }
    }
}