How to detect , if player is on ground when it collides with any object it should die, so then player should not die if it collides with sameobject in pit ?

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.