Script help for killing enemy

I’m new to using Unity and trying to make a simple 2D platform game. I’ve created a player and enemies in the game that are walking around on platforms. I’m stuck on how to script the enemies to get destroyed. What I’m trying to do is that when the player jumps on the enemy they should get destroyed, just as in games such as Mario Bros. I’ve been trying to attach a script on both the players feet to when they collide, the enemy gets destroyed and/or attach a script to the enemy when the players feet collides… but with no success.

Anyone got an idea how to solve this?

:smile:

Here’s my solution:

Have the monster have a script called “KillMe” that destroys it when called. Then setup a script like this on the bottom object with a collider on the player:

function OnCollisionEnter(hit : Collider)
{
hit.gameObject.SendMessageUpwards(“KillMe”, SendMessageOptions.DontRequireReceiver);
}

That should do it quite well.

Great, thanks! I’ll try it out straight away.

Was that solution successful?

Also, how would one go about doing the same thing with character that is a single object?

I suppose you could attach a collider without a mesh to the bottom of the character, but that could mess with the physics of the game.

Hey, would you mind posting the code for the enemy walking on the platforms? I’m sure that would help alot of people out! Thanks