Okay so I want to make it so that when my missiles collide with something they explode(terrain, object, ect), how would I set this up? Note I have downloaded the Detonator extension.
Currently I've got targets that go down just from getting hit, how would I arrage for the explosion made (most likely would use either the simple or tiny explosion if I use a premade one) to be what knocks the targets down?
And if you would so kindly provide some example code for the above questions? I'm just barely starting out using Unity so if you just tell me where to put it I might not quite get it. Thank you ahead of time.
var explosion : GameObject;
static var score : float;
//gives the missile its speed
function FixedUpdate () {
rigidbody.AddForce (transform.TransformDirection (Vector3.forward) * 100.0);
}
function OnCollisionEnter(collision : Collision) {
var contact : ContactPoint = collision.contacts[0];
var thisExplosion : GameObject = Instantiate (explosion, contact.point + (contact.normal * 5.0) , Quaternion.identity);
//here you can set a tag so when your missile hits different stuff it can add different scores or have different explosions
if (collision.gameObject.tag == "enemy")
{
score = score + 100;
Destroy (collision.gameObject);
Instantiate (explosion, contact.point + (contact.normal * 5.0) , Quaternion.identity);
}
}
Destroy (thisExplosion, 2.0);
Destroy (gameObject);
}