Animation for Attacks

Hi I am new to coding trying to use a script to play an animation for an attack and I get the following error

BCE0020: An instance of type ‘UnityEngine.Animation’ is required to access non static member ‘Play’.

#pragma strict

var Damage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
var Hammer : Transform;

function Update ()
{
    if (Input.GetButtonDown("Fire1"))
    {
        GetComponent<UnityEngine.Animation.Play>("attack");
        var hit : RaycastHit;
        if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
        {
            Distance = hit.distance;
            if (Distance < MaxDistance);
            {
                hit.transform.SendMessage("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
            }
        }
    }
}

Help plz

.Play is a function of the Animation class, try this instead.

GetComponent< Animation >().Play( "attack" ); :slight_smile:

I did that and I received 3 Errors
BCE0043: Unexpected token ), (12,41)
BCE0044: expecting ), found ‘.’. (12,24)
UCE0001: ‘;’ expected. Insert a semicolon at the end. (12,43)
:frowning:

Your problem is not related with animation. Those are code syntax errors.
Look at some scripting beginner series. That might help.