Game Development Reference
In-Depth Information
public class Rocket : MonoBehaviour {
public float timeOut = 3.0f;
public GameObject explosionParticle;
ParticleSystem _smokeTrail;
void Awake () {
_smokeTrail =
GetComponentInChildren<ParticleSystem>();
}
void Start () {
Invoke("KillObject", timeOut);
}
void OnCollisionEnter (Collision others) {
ContactPoint contactPoint = others.contacts[0];
Quaternion rotation =
Quaternion.Euler(Vector3.up);
GameObject.Instantiate(explosionParticle,
contactPoint.point, rotation);
KillObject();
}
void KillObject () {
if (_smokeTrail != null) {
_smokeTrail.Stop();
_smokeTrail.loop = false;
}
GameObject.Destroy(gameObject);
}
}
14. Then, we go back to Unity and add the Box Collider component to the rocket
object by going to Component | Physics | Box Collider .
Search WWH ::




Custom Search