Game Development Reference
In-Depth Information
{
// Wait a moment to ensure we are clear, then destroy the
//enemy object.
Destroy(gameObject,0.1f);
}
Now, play the game and fire the player's weapon at the enemy. When the bullets hit
the enemy, they will cease to exist!
You may be wondering why we used events and delegates for this when we could
have just used a script component reference. Well, let me ask you this, if you did not
know how events and delegates worked a page ago, do you know now? No? Well
then go over it and hopefully you will get it the second time around. Essentially,
each event is a type of delegate, and any object can listen to events.
Now you are ready for the future event and delegate work that we will be doing in
the rest of this topic, as much of that upcoming work will not work well with object
references. If you don't understand, give it another read-through.
Just for fun, let's give the enemy a particle effect when they are killed. First things
first, create a new Particle System object named EnemyDeathFX . As a skilled Unity
ninja, it is most likely that you already know how to build these, so I won't go into
the nitty-gritty of making awesome particle emitters. To help you out, we have
included some particle graphics for you to use; import the graphics from the folder
Sprites\Particles .
While I'm not going to describe how to create particles, I will, however, discuss a
small requirement that you will need to fulfill to make these particles work in a 2D
world. If your emitter has too much depth to it, the particles won't be in the camera
view of the Orthographic camera. Keep this in mind when building out the particles,
and test them frequently to ensure they look the way you want. Try and keep your
emitters very, very thin. Check out the following image; that thin line in the middle
is the particle system that we created. We really mean thin here.
 
Search WWH ::




Custom Search