Does Unity not like methods inside of other ones?

In Unity 5, I am trying to create a simple character controller for a cube. I have a plane parented to the bottom of the cube to check for collisions with the ground to reset a “grounded” bool variable. The compiler says:
CollisionChecker.cs(11, 45) Keyword ‘void’ cannot be used in this context
CollisionChecker.cs(11, 46) Unexpected symbol ‘(’
CollisionChecker.cs(16, 1) Parsing error
Here are the 2 pieces of code I have, one directly on the cube and the other on the parented plane.
Cube’s Code:

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {
	public Rigidbody player;
	public float moveBackwardMultiplier = 1;
	public float moveForwardMultiplier = 1;
	public float moveSidewaysMultiplier = 1;
	public float jumpForce;
	public float jumpMultiplier = 1;
	public bool grounded = true;
	void Jump () {
	while(grounded){
		if(Input.GetButtonDown("Jump")){
			grounded = false;
			Vector3 vectorJump = new Vector3 (0, jumpForce, 0);
			player.AddForce(vectorJump * jumpMultiplier);
	}	
	}
	}
	void Start() {
		player = gameObject.GetComponent<Rigidbody> ();
	}




}

Plane’s Code:

using UnityEngine;
using System.Collections;

public class CollisionChecker : MonoBehaviour {
	public PlayerController playerController;
	void Start() {
		playerController = gameObject.GetComponentInParent<PlayerController> ();
	}
	void FixedUpdate() {
		while(!playerController.grounded){
			void OnCollisionEnter(Collider other){
				playerController.grounded = true;
			}
		}
	}
}

If anyone could help me out with why my code is not working I would really appreciate it or even more so if they told me a better way of doing it than the way I am now.

For sure you can’t declare a function inside an other one ! You can just call it !

I don’t know many languages allowing that. Python, I think, but not C# !

Hello Just_Alerik,

i don’t think unity allows a function in a function but u can still achieve a similar result with this:

 using UnityEngine;
 using System.Collections;
 
 public class CollisionChecker : MonoBehaviour {
     public PlayerController playerController;
     
     private bool inTrigger = false;

     void Start() {
         playerController = gameObject.GetComponentInParent<PlayerController> ();
     }
     void FixedUpdate() {
         while(!playerController.grounded){
             if(inTrigger){
                playerController.grounded = true;
             }
         }
     }

     void OnCollisionEnter(Collider other){
          inTrigger = true;
     }
 }

Regards Faizan.