Game Development Reference
In-Depth Information
If it does hit an object with a collider, you will have it destroyed sooner. Because the potato should
roll or bounce a little first, it will have a delay also.
Create the OnCollisionEnter function:
11.
void OnCollisionEnter () {
//destroy the object this script is on 2 seconds after collision
Destroy(gameObject, 2f);
}
12.
Save the script.
13.
Add the script to the Sphere prefab in the Project view.
14.
Click Play, and test the new functionality.
The spheres now disappear 3 seconds after they are shot unless they hit something first.
With the basics sorted out, you may as well bring in the real ammo.
1.
From the right-click menu in the Project view, choose Import New Package,
Custom Package, and load Potato.unitypackage from the Chapter 8 Assets
folder.
The package includes a lone potato and a pile of potatoes that conveniently fit into the garden pots
from a previous import (Figure 8-3 ). The assets are added to the Imported Assets folder. You will also
find a prefab for each object in the Prefabs folder. Rather than using the default Diffuse shader, the
PotatoSkin material is using a Self Illuminated Diffuse shader to brighten the object slightly through
the use of the BoxHedge texture's alpha channel. To brighten the potatoes even more, you could
create an alpha channel on the Potato Skin texture and use it in place of the BoxHedge texture.
No texture, or a texture that has no alpha channel, defaults to white or fully self-illuminated and will
appear very flat.
Figure 8-3. The imported potato assets—looks like the Yukon Gold variety
 
Search WWH ::




Custom Search