Game Development Reference
In-Depth Information
currentFrame++;
if (currentFrame > = totalFrames)
{
currentFrame = currentStartFrame;
}
}
function Update()
{
if(Input.GetKey (KeyCode.UpArrow))
{
this.transform.position.z++;
SetAnimation("WALK_BACK");
}
else if(Input.GetKey (KeyCode.DownArrow))
{
this.transform.position.z--;
SetAnimation("WALK_FORWARD");
}
else if(Input.GetKey (KeyCode.LeftArrow))
{
this.transform.position.x--;
SetAnimation("WALK_LEFT");
}
else if(Input.GetKey (KeyCode.RightArrow))
{
this.transform.position.x++;
SetAnimation("WALK_RIGHT");
}
else
{
SetAnimation("IDLE");
}
}
function LateUpdate ()
{
if(Time.time > nextFrame)
{
nextFrame = Time.time + timeBetweenFrames;
UpdateSprite();
}
}
Step 7. Play. The sprite will now be animated with the correct
sequence of frames depending on the direction it is moving.
Search Nedrilad ::




Custom Search