Animating a 2D Sprite

Hello everyone,

i guess i have been asking a lot lately. sorry.
so i’m trying to animate a 2D sprite using javascript
i don’t wanna loop the animation. it’s just going from picture 1 to picture 2 to pictrue 3 then stay on pictrue 3 until i stop moving or something else. the thing i’ve been trying to animate is this picture, my player is rigidbody cube

thanks.

Well I don’t know JavaScript very well, I am a C# guy. So this example will hopefully work. This is the simplest way I can think of how to change the mainTexture of your material, without using an iterator. I would do an iterator but like I said, I’m not used to JS lol. Hope this leads you in the right direction. You’ll assign the textures to the “frames” array in the inspector. This example is my attempt at JS.

var frames : Texture2D[];
var delay : float = 1f;

function Start()
{
    Animate();
}

function Animate()
{
    renderer.material.mainTexture = frames[0];
    yield WaitForSeconds(delay);
    renderer.material.mainTexture = frames[1];
    yield WaitForSeconds(delay);
    renderer.material.mainTexture = frames[2];
    
}