Game Development Reference
In-Depth Information
6.
Repeat for the rest of the sprites.
7.
Close the editor, and click Play to see the difference.
The stork doesn't have a lower beak or a payload yet, but you can get him moving across the
scene in the meantime. Because he's just doing a simple fly-by with no obstacles to navigate, using
physics would be overkill. A simple transform animation will do the job. In order to retain control of
the animations of the various parts of the stork and his payload, you will put him on a parent object.
8.
Create a new C# Script, and name it FlyBy .
9.
Create a variable for speed:
public float speed = -5f; // send the 2d sprite left
In its Update function, add:
10.
transform.Translate ( speed * Time.deltaTime, 0, 0);
Because of the Camera GUI's orientation, world x, y, z space is also screen x, y, z space, so the
minus x value will send the object from right to left.
11.
Save the script.
12.
Focus in on the Stork_0 in the Scene view.
13.
Create an Empty GameObject, and name it Stork Group .
14.
Assign it to the Sprite layer.
15.
Add the FlyBy script to Stork Group.
16.
Add the Stork_0 object to Stork Group.
17.
Position the Stork Group to the right side of the Game view, just out of view.
18.
Click Play, and watch the stork flap his way across the screen.
The stork will make several trips across the screen throughout the game, so you will want to save
the starting location, as well as deactivate him when he's reached the other side. The location is
calculated in world space, and the screen bounds or viewing frustum are relative to the Camera GUI.
You are probably wondering why you aren't going to Destroy and Instantiate the stork as you have
with other characters that come and go. If you plan on developing games for mobile at some point,
you will discover that the Destroy / Instantiate method is rather costly. Typically in mobile, objects
that make several appearances are deactivated and reactivated. It tends to require more work on
your part, but it is a worthwhile method of controlling temporary objects to try out.
The first thing to do is to see what happens when the object is deactivated and then reactivated.
19.
Select the Stork Group.
20.
Click Play, and then deactivate it from the top of the Inspector when it is
about half way across the screen.
21.
Now reactivate it.
 
Search WWH ::




Custom Search