Game Development Reference
In-Depth Information
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
Vector3 explosionPos = transform.position;
float explosionRad = transform.localScale.magnitude;
piece.rigidbody.AddExplosionForce(explosionPower,
explosionPos,
explo-
sionRad);
//If life time is spiecified,
//destroy the piece after it if(pieceLifetime >
0){
Destroy(piece, pieceLifetime);
}
64.
}
65.
}
66.
67.
//Inform other scripts that the object has been broken
68.
SendMessage("OnBreak", SendMessageOptions.DontRequireReceiver);
69.
70.
//Finally, destroy the breakable
71.
Destroy(gameObject);
72.
73.
}
74.}
Listing 59: A script to make an object breakable
Search WWH ::




Custom Search