Game Development Reference
In-Depth Information
This time the zombies have a 1-in-3 chance of disappearing on the first hit or near hit, making it
easier to clear the varmints out of the garden. With all of this fire power, you are probably thinking
the plants should suffer as well. A simple little script with a Terminator function will do the trick.
1.
Create a new C# Script in the Game Scripts folder, and name it
PlantRemover .
2.
Add the following variables:
public int hardiness = 1; // amount of damage required to destroy the plant
int damage = 0; // accumulated hit damage
Create the Terminator function:
3.
void Terminator (int newDamage) {
damage += newDamage; // add more damage from
if (damage > hardiness) Destroy(gameObject);
}
4.
Save the script, and add it to each of the plant prefabs, adjusting the
Hardiness where necessary. (Cabbage, for example, might require
40 damage points to get rid of.)
5.
Add a Sphere Collider, with Is Trigger checked, to each of the short plants
and a Box Collider to the taller ones, adjusting as necessary.
6.
Activate your Plant Zones, and test the new addition to your game play.
Post-Processing Effects
If you are using Unity Pro, there is one more effect you may want to try. Because the slug is electric
in your little game, you might want a glow effect around him. Fake glows can be achieved for lights
through the use of a billboard plane. There's even a parameter that creates the effect for you in the
Light component. Other than the alpha sorting, it is fairly efficient. But a true glow is calculated after
the frame has been drawn to the screen through the use of shaders. For this you will require Unity
Pro's Image Effects.
1.
If you are using Unity Pro, import the Image Effects (Pro Only) package.
An Image Effects folder is added in the Standard Assets folder. It consists of a few textures and a
lot of shaders and scripts. Because it is a post-process effect, the component will be added to the
main camera.
2.
Drag the Slug prefab into the Staging area so it can be seen in the Game view
(as rendered through the Main Camera).
3.
Open the Main Camera Target's hierarchy, and select the Main Camera.
4.
From the Component menu, Image Effects, Bloom and Glow, select Bloom
(Optimized) (Figure 8-41 ).
 
Search WWH ::




Custom Search