- Home /
OnCollisionEnter not working?
Hello! I need some help with this issue that I don't understand why I have...
I have a script titled "TouchDeath" to where when my Player touches the Enemy, or collide with each other, the Player will die.Now I'm using the very basic but helpful codes here:
function OnCollisionEnter( collision : Collision )
{
if ( collision.gameObject.tag == "Player" )
I have placed the script on my Player and tagged the Enemy "player" (funny enough it works) and it has been working for a while! I've updated my game, done some little changes here and there, and I get a email saying they can still touch the Enemy and get away with it....
Oddly, this script has stopped working... I've checked the game and for some reason, there is this VERY thin line in-between my Player and my Enemy when I collide into him. This confuses me because how is the script supposed to work, when the colliders can't seem to touch each other?!
I'm not sure what is going on and I really need some guidance on this. Much appreciated to whoever can help me! :)
You need to add a Debug.Log() statements to figure out what is going on:
function OnCollisionEnter( collision : Collision )
{
Debug.Log("I collided with: "+collision.gameObject.name+", "+collision.gameObject.tag);
if ( collision.gameObject.tag == "Player" )
I have added the Debug.Log and when I touch the Enemy, nothing seems to happen still! There is no debug.log within the console when I touch the Enemy....
Answer by Halo500 · Oct 12, 2013 at 12:18 AM
Nevermind! I have just found an answer!
Instead of using "OnCollisionEnter", I used:
function OnControllerColliderHit(hit : ControllerColliderHit) {
if(hit.gameObject.tag == "Player")
And it works fine! Since there was no collider on my Player (unless you count the Character Controller as one), there was no collision with two colliders, only a collider with the controller.
Thanks for helping out though!! :D