Making my ball jump only when grounded

Hey everyone, I followed one of unity’s own tutorials called roller ball (
Now I went a bit further and I wanted to make the ball jump aswell, and that works fine, the only thing I have noticed is that I can make it fly even when it is in the air. So I need to make it only fly when it is grounded. I have looked a lot of youtube tutorials before I came here, and they work badly at best. So I am wondering, how would you guys solve this? in advance thank you.
Best regards Carl

using UnityEngine;
using System.Collections;

public class b : MonoBehaviour {

public	float	speed;	

private	Rigidbody	rb;	

private	bool	isJumping;	

// Use this for initialization
void Start () {
	rb = GetComponent<Rigidbody> ();	


// Update is called once per frame
void FixedUpdate () {
	float	moveHorizontal	=	Input.GetAxis	("Horizontal");	
	float	moveVertical	=	Input.GetAxis	("Vertical");	

	Vector3 movement = new	Vector3 (moveHorizontal, 0.0f, moveVertical);
	rb.AddForce (speed * movement);
	if (Input.GetKeyDown(KeyCode.Space)) {

void	Jump	()	{
	Vector3 Up = new	Vector3 (0, 10, 0);
	rb.AddForce (speed * Up);	


Privacy & Terms