Game Development Reference
In-Depth Information
Figure 10-4. Remove the Ball and Ball User Control scripts from the Land Mine game object in the Inspector
Finally, you will need a script that tells the Land Mine to explode if the player character comes in
contact with it, destroying the land mine and killing the player character. In the Project panel open
Assets รค Script, then create a new script named LandMineExplosion and open it in MonoDevelop.
Edit the code as follows:
#pragma strict
public var victim : GameObject;
public var explosionPrefab : GameObject;
function Start () {
victim = GameObject.FindWithTag("Player");
}
function OnTriggerEnter (collider : Collider) {
if (collider.gameObject == victim) {
Explosion();
}
}
function Explosion () {
victim.GetComponent(GoRagdoll).GotoRagdoll();
Instantiate (explosionPrefab, transform.position, Quaternion.identity);
Destroy(gameObject);
}
This code breaks down as follows:
(1) private var victim : GameObject;
Declare a private GameObject type reference variable named victim for the
player character reference.
1.
(2) public var explosionPrefab : GameObject;
 
Search WWH ::




Custom Search