Allowing only a single key stroke while object isn't colliding with another object

So I’m rather new to Unity and am trying to create a minimalist platformer. I’m using a sphere for the player and it moves on cubes. I’m using the following script for the player controller. I would like to only allow the moveUp method to happen if the sphere is currently colliding with a cube allowing me enforce a single jump at a time. Is there an easy of concise way to enforce this?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour {

	public GameObject player;
	public float movespeed;
	public float upforce;
	private Rigidbody2D rb;


	// Use this for initialization
	void Start () {
		rb = player.GetComponent<Rigidbody2D> ();
	}
	
	// Update is called once per frame
	void Update () {
		if (Input.GetKeyDown (KeyCode.W)) {
			moveUp ();
		}else if (Input.GetKey (KeyCode.A)) {
			moveLeft();
		}else if (Input.GetKey (KeyCode.D)) {
			moveRight();
		}
	}

	public void moveUp(){
		rb.AddForce(new Vector3(0, upforce, 0));
	}
	public void moveRight(){
		rb.AddForce(new Vector3(movespeed, 0, 0));
	}
	public void moveLeft(){
		rb.AddForce(new Vector3(-movespeed, 0, 0));
	}
}

As with all things in programming, there are many valid ways to get what you want.

The most typical way to establish a “grounded” check involves raycasting - Physics.Raycast() with a ray whose origin is the player position and whose direction is “down” (whatever direction “down” is in your game, e.g. Vector3.down). This is how nine out of ten games check whether something is “grounded”.

Another way involves using colliders / collision. For instance, the OnCollisionStay() built-in method (along with its sibling methods like OnCollisionEnter, OnTriggerStay, etc) is generally the preferred way for a MonoBehavior to gather information about its physical interactions.

In either case, you’re gathering information and responding to certain conditions, like whether the player is touching the ground. Then you only allow the jump code to execute if that condition is true.

Best of luck moving forward,