Detect collision between player and ground Unity3D
<p>I'm still learning Unity and right now I'm trying to make my player able to jump. Of course I don't want my player to be able to jump on forever, so my idea was to only enable jumping when the player is in contact with a floor object. This is the code I have so far:</p>

<pre><code>public class PlayerController : NetworkBehaviour
{

    public float speed;             // Player movement speed
    private bool grounded = true;   // Contact with floor

    private Rigidbody rb;

    void Start()
    {
        rb = GetComponent&lt;Rigidbody&gt;();
    }

    // Show a different color for local player to recognise its character
    public override void OnStartLocalPlayer()
    {
        GetComponent&lt;MeshRenderer&gt;().material.color = Color.red;
    }

    // Detect collision with floor
    void OnCollisionEnter(Collision hit)
    {
        if (hit.gameObject.tag == "Ground")
        {
            grounded = true;
        }
    }

    // Detect collision exit with floor
    void OnCollisionExit(Collision hit)
    {
        if (hit.gameObject.tag == "Ground")
        {
            grounded = false;
        }
    }

    void FixedUpdate()
    {
        // Make sure only local player can control the character
        if (!isLocalPlayer)
            return;

        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");

        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

        rb.AddForce(movement * speed);

        // Detect space key press and allow jump if collision with ground is true
        if (Input.GetKey("space") &amp;&amp; grounded == true)
        {
            rb.AddForce(new Vector3(0, 1.0f, 0), ForceMode.Impulse);
        }
    }
}
</code></pre>

<p>But it seems <code>OnCollisionEnter</code> and <code>OnCollisionExit</code> never trigger. So the player is still able to jump whenever he wants. Am I doing something wrong?</p>

<p>Edit: It seems <code>OnCollisionEnter</code> and <code>OnCollisionExit</code> are triggered perfectly fine. It's just the if statements returning false. I have no idea why though.</p>

<p><code>if (GameObject.Find("Ground") != null)</code> returned true.</p>

<p>Edit 2: Strangely enough both of these return <code>Untagged</code>:</p>

<pre><code>Debug.Log(hit.gameObject.tag);
Debug.Log(hit.collider.tag);
</code></pre>