Game Development Reference
In-Depth Information
{
mesh = GetComponent(MeshFilter).mesh;
texture = renderer.material.mainTexture;
renderer.material.shader = Shader.Find( "Sprite" );
timeBetweenFrames = 1.0/framerate;
}
function Update()
{
if(Input.GetKey (KeyCode.UpArrow))
{
this.transform.position.z++;
}
else if(Input.GetKey (KeyCode.DownArrow))
{
this.transform.position.z--;
}
else if(Input.GetKey (KeyCode.LeftArrow))
{
this.transform.position.x--;
}
else if(Input.GetKey (KeyCode.RightArrow))
{
this.transform.position.x++;
}
}
Step 3. Play. The sprite will be moveable with the arrow keys.
The image on the sprite will be blurred, as it is not yet set up
correctly.
Step 4. Next we need to create some simple data structures to store
the frame size as well as the starting frames and length for each
animation sequence. A neat way to do this is to create simple class
structures to store the information. When named with meaningful
variable names, the editor displays a nice way to edit the information.
Modify SpriteManagment.js by adding the code in Listing 3.19 to the
very top of the script.
Step 5. Select the Plane child object of basicPlane in the
Hierarchy. In the Inspector, locate the attached SpriteManager
script as shown in Figure 3.17 . Note how the variables from
the classes in the script are displayed in the Inspector. This
makes them easy to recognize and edit. This could have been
achieved easily using Vector2 data types; however, it would
have been messier. Enter the values into the Inspector for
the sprite dimensions and animation sequences as shown in
Figure 3.17 .
Search Nedrilad ::




Custom Search