The public bool will not change unless i set it

I’m trying to get my game to able movement when colliding
with the ground and no control available when in the air.

The problem:

Ground is not turning to false when off a collider.

Cant get it to say “your off” when i’m off the ground, which should mean i have no control.

The code to stop all movement only works if i change it in the inspector.

I have:

Set print functions to see what is working, this helps to know whats working and whats not.

Added rigid bodies to other objects, did nothing.

Void on awake to say that ground was true or false, did nothing.

Separating movement into its own function, That helped simplify my code.

I’ve checked all over the site as well as Google and saw that my code should work, but is not.

I attached a Sample of the code for reference:

using UnityEngine;
using System.Collections;

public class PlayerController2 : MonoBehaviour {
	public float speed = 1;
	public float jump = 1;
	public bool Ground;   

	void OnCollisionEnter2D(Collision2D coll){
		if (coll.gameObject.tag == "Enemy")
			print ("ow");

		if (coll.gameObject.tag == "Ground")
			print ("Rollin 'Ground is true'");
			bool Ground = true;
	}

	void OnCollisionExit2D(Collision2D coll){
		if (coll.gameObject.tag == "Enemy")
			print ("Yay");
		
		if (coll.gameObject.tag == "Ground")
			print ("Rollin 'Ground is false'");
			bool Ground = false;
	}

    void Update () {
			if (Ground == true) {
			Movement ();
			}
			if (Ground == false) {
			print ("Your off");
			}
		}

	void Movement () {
	
		if (Input.GetKey (KeyCode.RightArrow)) {
			transform.position += new Vector3 (speed * Time.deltaTime, 0.0f, 0.0f);
		}
		
		if (Input.GetKey (KeyCode.LeftArrow)) {
			transform.position -= new Vector3 (speed * Time.deltaTime, 0.0f, 0.0f);
		}
		
		if (Input.GetKey (KeyCode.UpArrow)) {
			transform.position += new Vector3 (0.0f, jump * Time.deltaTime, 0.0f);
		}
		
		if (Input.GetKey (KeyCode.DownArrow)) {
			transform.position -= new Vector3 (0.0f, jump * Time.deltaTime, 0.0f);
		}
		
		if (Input.GetKeyDown ("space")) {
			speed = speed * 2;
			print ("Space is Down");
		}
		
		if (Input.GetKeyUp ("space")) {
			speed = speed / 2;
			print ("Space is Up");
		}
	}
}

Well there’s a bit of code here, but let’s start off with this.

You have several calls that are like this:

         if (coll.gameObject.tag == "Ground")
             print ("Rollin 'Ground is false'");
             bool Ground = false;

Based on your indentation, it seems like you think both of these lines will be executed only if your predicate (the statement inside your if(...)) is true. But that’s not the case.

If you choose to omit brackets after an if-statement, only the next statement will be executed.

That’s why it’s best practice to always use brackets with an if-statement.

Start off by changing all instances like the one above to this:

         if (coll.gameObject.tag == "Ground") {
             print ("Rollin 'Ground is false'");
             bool Ground = false;
         }

And we’ll continue from there.