How to make my tank not move on air?

I’m using a very simple script:

using UnityEngine;
using System.Collections;

public class TankControl : MonoBehaviour
{
public float moveSpeed = 10f;
public float turnSpeed = 50f;

void Update ()
{
	if(Input.GetKey(KeyCode.W))
		transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);

	if(Input.GetKey(KeyCode.S))
		transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);
	
	if(Input.GetKey(KeyCode.A))
		transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
	
	if(Input.GetKey(KeyCode.D))
		transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
}

}

But my tank moves even when it is in the air. How can I make it move only when its on land. I’m newer to unity so please post a script I can use, or edit this one. I want the script to make the tank go forward and backwards and rotate (like a real tank) not turn. Thanks!!!

this can be done by checking the ground by two method one with the ray

RaycastHit hit;

if (Physics.Raycast (transform.position, -Vector3.up, out hit))
{

print(hit.collider.name);
Debug.DrawLine(transform.position, hit.point);


if(hit.collider.tag== "ground ")
{
    your code here to move ;
}
}

you can also do this by oncollisionStay if the oncollisionstay with the ground you can wrie the code for the moveing the tank

You’ll need to manually check if you’re over the ground or not. Look at Unity - Scripting API: Physics.Raycast for ideas. Good luck!