- Home /
Mario-Like Enemy Death System Not Working
I wrote this script that is supposed to delete the parent game object (the enemy) when something, not just the player, collides with the object this script is attached to. When I jump on the enemy, it does nothing and has no console errors. Here is my script:
function OnCollisionEnter( collision : Collision )
{
Destroy(transform.parent.gameObject);
}
edit
I even tried another way of doing it, which uses the player to detect collisions, and it didn't work either. Here is the script:
#pragma strict
function OnCollisionEnter (col : Collision)
{
Debug.Log("Enemy About To Be Slain"); //to test collisions
if(col.gameObject.name == "Enemy")
{
Debug.Log("Enemy Slain"); //to test the collider object name thingy
Destroy(col.gameObject);
}
}
Possibly your collision hook isn't being called at all. Recommend you follow through some tutorials, such as this one.
Answer by Yinja · Aug 12, 2014 at 03:12 AM
The OnCollisionEnter() you posted looks good. Try putting an debug log to verify that this function is being called.
function OnCollisionEnter( collision : Collision ) {
Debug.Log("I made it to this point!");
Destroy(transform.parent.gameObject);
}
I tried that, and it seems that the function isn't even being called. I am not sure as to how to fix this though, as the script is attached to the enemy and both the player and the enemy has a collider.
Your answer
Follow this Question
Related Questions
Attack Player if Enemy is hit 0 Answers
How to access a bool of a specific clone in a collision 1 Answer
Fist Punch Collision 0 Answers
Makeing something Blow-up 3 Answers
Multiple Enemy Collision Help 0 Answers