All right, I've been looking and testing all sorts of examples and answers, the problem is simple yet I fail to get it right.
I have a small prop (a barrel) and I want to shoot it with a projectile and kill it after 2 hits (for the arguments' sake)
Now, for the prop I have this from the fps example:
var hitPoints = 100.0;
var detonationDelay = 0.0;
var deadReplacement : GameObject;
function ApplyDamage (damage : float) {
if (hitPoints <= 0.0)
return;
hitPoints -= damage;
if (hitPoints <= 0.0) {
Invoke("DelayedDetonate", detonationDelay);
}
}
function DelayedDetonate () {
BroadcastMessage ("Detonate");
}
function Detonate () {
Destroy(gameObject);
if (deadReplacement) {
var dead : GameObject = Instantiate(deadReplacement, transform.position, transform.rotation);
}
}
and for the projectile, this:
var explosion : GameObject;
function OnCollisionEnter( collision : Collision ){
var contact : ContactPoint = collision.contacts[0];
var rotation = Quaternion.FromToRotation( Vector3.up, contact.normal );
var instantiatedExplosion : GameObject = Instantiate(explosion, contact.point, rotation );
if (collision.gameObject.tag=="PreciousWreckageBarrels")
SendMessage("ApplyDamage",5.0,SendMessageOptions.DontRequireReceiver);
}
function FixedUpdate () {
rigidbody.AddForce (transform.TransformDirection (Vector3.forward) * 6000.0);
}
Tagged the prop correctly, did everything in my humble powers. Should I stop scripting? :)
Any help, greatly appreciated.