My Animation Only Play Once? (Noob)

First One Excuse My English And This Is My Email To Contact Me macroarcadeyt@gmail.com

My Animation Only Play One Time I put a script for animate it I put my 3D model in legacy with all animations in the script and in the “animation” (not in the animator) and it supose to make idle animation and then walk in circles but it only make the idle animation and it do it only one time why this? :confused: :frowning: Im desesperated pls answer me
PD I See a tutorial to make the script and in the tutorial function it perfectly, I use it in two diferent version of unity and it make the same error and I use like 3 or 4 diferent scripts :confused:

this is the error that appear in the console

MissingMethodException: UnityEngine.Animation.play
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.ProduceExtensionDispatcher ()
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create ()
Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object[] args)
Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target, System.String name, System.Object[] args)
Boo.Lang.Runtime.RuntimeServices+c__AnonStorey15.<>m__9 ()
Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args)
UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args, System.Type scriptBaseType)
IA.Nada () (at Assets/IA/IA.js:78)
IA.Update () (at Assets/IA/IA.js:51)

And this is the script:

//Estado var Estado : int = 0;

//Animaciones

var nada : AnimationClip;

var caminar : AnimationClip;

var correr : AnimationClip;

var atacar : AnimationClip;

var morir : AnimationClip;

//Valores

var pat : float= 0; var patu : boolean= true;


function Start () {

}

function Update () {

    if (pat < 0){
        patu= false;
        estado= 0;
    }

    if (pat > 10){
        patu= true;
        estado= 1;
    }

    if (patu == true){

        pat -= 1 *Time.deltaTime;
    }

    if (patu == false){

        pat += 1 *Time.deltaTime;
    }

    if (Estado == 0){//nada
        Nada ();
    }

    if (Estado == 1){//patrullar
        Patrullar ();
    }

    if (Estado == 2){//perseguir
        Perseguir ();
    }

    if (Estado == 3){//atacar
        Atacar ();
    }

    if (Estado == 4){//morir
        Morir ();
    }

    if (Estado == 5){//esquivar
        Esquivar ();
    } }


function Nada () {

    GetComponent.<Animation>().play (nada.name);

}

function Patrullar () {

    transform.Rotate (Vector3 (0,120,0)*Time.deltaTime);

    transform.Translate (Vector3 (0,0,1)*Time.deltaTime);

    GetComponent.<Animation>().play (caminar.name);

}

function Perseguir () {

    GetComponent.<Animation>().play (correr.name);

}

function Atacar () {

    GetComponent.<Animation>().play (atacar.name);

}

function Morir () {

    GetComponent.<Animation>().play (morir.name); }

function Esquivar () {

    GetComponent.<Animation>().play (correr.name);

}

If you click on your animation object in your Project view you should be able to set it to loop from the inspector.
Regarding your code, you should learn about “else if” and “switch”. It will improve the quality of your code.

Looks like the problem is that you are calling Animation.play which doesn’t exist. Animation.Play exists though. Upper and lower case are important.

If you turn on type safe compilation with #pragma strict you can catch these errors early. Also you had a typo with estado and Estado.

See if it works with those fixes.

#pragma strict

//Estado 

var Estado : int = 0;

//Animaciones

var nada : AnimationClip;
var caminar : AnimationClip;
var correr : AnimationClip;
var atacar : AnimationClip;
var morir : AnimationClip;
 
//Valores
 
var pat : float= 0; 
var patu : boolean= true;

function Update()
{
    if (pat < 0)
    {
        patu = false;
        Estado = 0;
    }

    if (pat > 10)
    {
        patu = true;
        Estado = 1;
    }

    if (patu == true)
    {
        pat -= 1 * Time.deltaTime;
    }

    if (patu == false)
    {
        pat += 1 * Time.deltaTime;
    }

    if (Estado == 0)
    {
        Nada();
    }

    if (Estado == 1)
    {
        Patrullar();
    }

    if (Estado == 2)
    {
        Perseguir();
    }

    if (Estado == 3)
    {
        Atacar();
    }

    if (Estado == 4)
    {
        Morir();
    }

    if (Estado == 5)
    {
        Esquivar();
    }
}

function Nada()
{
    GetComponent.< Animation > ().Play(nada.name);
}

function Patrullar()
{
    transform.Rotate(Vector3(0, 120, 0) * Time.deltaTime);
    transform.Translate(Vector3(0, 0, 1) * Time.deltaTime);
    GetComponent.< Animation > ().Play(caminar.name);
}

function Perseguir()
{
    GetComponent.< Animation > ().Play(correr.name);
}

function Atacar()
{
    GetComponent.< Animation > ().Play(atacar.name);
}

function Morir()
{
    GetComponent.< Animation > ().Play(morir.name);
}

function Esquivar()
{
    GetComponent.< Animation > ().Play(correr.name);
}