i have asprite sheet in which i need to move frames 1-11 only once while 12-17 in a loop till a user clicks on a button on the sprite…
i wrote a script which plays the sprite once and it is working fine but dont know how to implement the looping property.
any help would be appriciated.
enum spriteState { Idle, FirstFrames, LoopFrames }
var spritePlayState : spriteState;
function Start()
{
// Set the state like this :
spritePlayState = spriteState.FirstFrames;
}
function Update()
{
switch( spritePlayState )
{
case spriteState.Idle :
Idle();
break;
case spriteState.FirstFrames :
FirstFrames();
break;
case spriteState.LoopFrames :
LoopFrames();
break;
}
}
function Idle()
{
// do nothing, or just play first frame
}
function FirstFrames()
{
// Use your play script here to cycle between frames 1 and 11
// from here you can also change states
if (Input.GetKeyDown(Keycode.Space))
{
spritePlayState = spriteState.LoopFrames;
}
// or instead change state when frame reached 11 =]
}
function LoopFrames()
{
// Use your play script here to cycle between frames 12 and 17
// then with another condition return to Idle state
// spritePlayState = spriteState.Idle;
}
This is probably too complex for what you are after, but anyway, here’s a state engine =]