This issue giving me very much problem , i have tried with x position still it is not working. if player is onground and collides any object he should die. inside pit it should not die.
You can give the colliders different tags and ckeck them.
Code, if you use a CharacterCollider:
void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.collider.tag == "OnGround")
{
...
}
}
Else:
void OnCollisionEnter(Collision collision)
{
if (collision.collider.tag == "OnGround")
{
...
}
}
Thank you for answer.