Howdy Unity,
Just a quick question here. Building a space shooter, adding in “motherships” (larger enemies). I want to make certain parts of them vulnerable to damage. To do this, I add a Script called “ArmouredDamage” to the main mothership gameObject which has an exposed array of gameObjects. Each of the vulnerable spots is a gameObject that is a child of the mothership. Both the mothership and the vulnerable spots have colliders attached to them.
Anyways. The point is I use a really basic script to make all enemies take damage…it is…
var health = 100.0;
var explosion : ParticleEmitter;
function TakeDamage (damage) {
health -= damage;
Debug.Log("HIT!");
if (health <= 0)
{
if (explosion)
{
Instantiate (explosion, transform.position, transform.rotation);
}
Destroy(gameObject);
}
}
This. Whenever a laser collides with a collider, it does this…
function OnCollisionEnter (collision : Collision) {
Kill();
collision.gameObject.SendMessage("TakeDamage", damage, SendMessageOptions.DontRequireReceiver);
}
function Kill()
{
Destroy(gameObject);
}
My problem is the children gameobjects won’t take damage! I’m guessing this has to do with the SendMessage call or something, but I can’t really find any info on it. I know that there’s nothing wrong with the children gameobjects (I detached them from the main mothership and they take damage just fine) so it has to be something along the lines that SendMessage isn’t recieving them because they’re children or something…I know the lasers ARE colliding with the vulernable spots for sure, but the message isn’t being recieved.
Thanks for any help guys!