Game Development Reference
In-Depth Information
Bomb Obstacle
Dramatic fiery explosions are created much the same way, only with fire and smoke particle systems
along with additional special touches like adding light and sound. The Sample Assets package has a
fantastic explosion example complete with fire and smoke materials and textures.
The Ball prefab in the Sample Assets package looks dark and ominous, so it will make a great bomb.
Drag it from the Assets ➤ Sample Assets ➤ Vehicles ➤ Rolling Ball ➤ Prefabs folder onto the scene,
name it Bomb, set Tag to Untagged, and give it a Transform.position of (0, 9.5, 20). Remove the
Ball and Ball User Control Script components by clicking on the gear icon and selecting Remove
Component from the drop-down menu.
In the Project panel Assets ➤ Scripts folder, create a new script named BombExplosion and open it
in MonoDevelop. Edit the code to the following:
#pragma strict
public var victim : GameObject;
public var prefab : GameObject;
function Start () {
victim = GameObject.Find("Third Person Character Ragdoll");
}
function OnCollisionEnter (collision : Collision) {
if (collision.gameObject.name == "Third Person Character Ragdoll") {
Explosion();
}
}
function Explosion () {
victim.GetComponent(GoRagdoll).GotoRagdoll();
Instantiate (prefab, transform.position, Quaternion.identity);
Destroy(gameObject);
}
Save the script and attach it to the Bomb game object. Breaking it down:
(1) public var victim : GameObject;
public var prefab : GameObject;
Declare two reference variables, victim and prefab , of type GameObject .
1.
(2) victim = GameObject.Find("Third Person Character Ragdoll");
In the Start() function, assign the Third Person Character Ragdoll reference
to victim .
2.
(3) if (collision.gameObject.name == "Third Person Character Ragdoll") {
Explosion();
}
 
Search WWH ::




Custom Search