I tried searching the forums and google but I haven’t been able to find my answer.
I am creating an adventure game and I am stuck on one part of my game. I have already coded when the enemy touches my character, the character is destroyed by using the destroy(GameObejct). My question now is that I want my character to be able to jump on top of the enemy and destroy it but still have it when the enemy touches you, you die and lose a life.
I’m not really that great at coding and this is my first game so a little guidance is appreciated.
You could make that simply by creating an trigger on the head/top of the enemy
Enemy>
Box (Tick is Trigger and place it on the head of the enemy then attach the script here) /!\ Put the Box under your enemy hierarchy !
var Enemy: GameObject; // Attach the Enemy who will be destroyed
function OnTriggerEnter (other : Collider) {
if (other.gameObject.tag == "Player") {
Destroy(Enemy.gameObject);
}
}
Hello, thanks for the quick reply.
I have done exactly what you have said but I have a slight issue…
When I jump on the top, the box on the top is destroyed but the enemy below it is not. My character goes through the box to destroy it and ends up touching the enemy which then kills by player.
Just for a test I am using cubes created within Unity