system
1
am new to unity i used this script to shoot a projectile from my rocketlaucher:
var projectile : Rigidbody;
var speed = 20;
function Update () {
if ( Input.GetButton ("Fire1")) {
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));
Destroy (clone.gameObject, 15);
}
}
when my projectile hits another object i whant it to make an explosion
can anyone help plz;
Instantiate an exlosion prefab when the rocket hits an object.
function OnCollisionEnter(col: Collider){
var Explode : Transform;
Instantiate(Explode, transform.position, transform.rotation);
}
That should work as a basic Instantiate script,attach it to your rocket. and download some explosion prefabs from here:
http://unity3d.com/support/resources/unity-extensions/explosion-framework.html
Creating an explosion on collision with another gameobject is essentially a two step process:
- detect the collision
-
instantiate your explosion effect (generally a particle system of some sort)
The second link there even goes over explosions specifically. Good luck with your project!