As mentioned, use OnCollisionEnter instead. Also, I have OCD and your code irked me so I had to make it pretty. Note: I removed your While statement as it was being used oddly.
using UnityEngine;
public class PlayerController : MonoBehaviour {
public float speed;
public float jumpHeight;
private Rigidbody2D rb;
private bool isGrounded;
void Start () {
rb = GetComponent<Rigidbody2D>();
}
void Update () {
if (isGrounded && Input.GetKeyDown(KeyCode.W)) {
Vector2 jump = new Vector2(0.0f, jumpHeight);
rb.AddForce(jump, ForceMode2D.Impulse);
}
}
void FixedUpdate () {
float move = Input.GetAxis("Horizontal");
Vector2 movement = new Vector2(move, 0.0f);
rb.AddForce(movement * speed);
}
void OnCollisionEnter (Collision coll) {
isGrounded = true;
}
void OnCollisionExit (Collision coll) {
isGrounded = false;
}
}