Game Development Reference
Listing 3.5 Script to Swap Frames on a Texture Atlas According
to a Set Frame Rate
var textures: Texture2D;
timeBetweenFrames = 1.0/framerate;
function LateUpdate ()
if(Time.time > nextFrame)
nextFrame = Time.time + timeBetweenFrames;
if(currentFrame > = textures.length)
currentFrame = 0;
Step 12. Play. The sprite will be animated.
Step 13. To change the speed at which the animation plays, select
the plane in the Hierarchy and locate the Framerate variable of the
AnimatedSprite component in the Inspector. This value controls the
number of frames drawn per second. Change it to 100 to see the
animation play faster and change it to 1 to see it run slower.
Step 14. Download Chapter Three/background.psd from the Web site.
Add a new plane to the scene behind the sprite and put this new texture
on it. It is a city background scene. Stretch the plane out to accommodate
the texture. Set the material shader to Sprite to make it display correctly
without lighting. If the image is upside down, rotate the plane by 180°
around the y axis.
image scrolling code from Chapter Two, repeated here in Listing 3.6 for
Step 16. With this new plane selected, change the UVSpeed to (0.1,0) in
Step 17. Play. The background will scroll, making the character appear to
walk along the street.