Locking cursor to middle of screen not working

Hey!

So I’m attempting to make a script that locks the mouse cursor to the center of the screen. I’m trying to use a method that sets a bool to true if “F” is pressed. If said bool is set true, the cursor is then locked to the middle of the screen. Sadly, it’s just not working. Here is my code:

using UnityEngine;
using System.Collections;

public class CursorLock : MonoBehaviour {

	public bool cursorLocked;

	void Start () {
		cursorLocked = false;
		Cursor.visible = true;
	
	}

	void Update () {

		if (cursorLocked) {
			Cursor.lockState = CursorLockMode.Locked;
		} else {
			Cursor.lockState = CursorLockMode.None;
		}
	
	}

	 bool CursorCheck (bool cursorLocked) {
		
		if (Input.GetKey (KeyCode.F)) {
			cursorLocked = true;
		} else {
			cursorLocked = false;
		}
		return cursorLocked;
	}
}

Originally, I had my script set to call the method in the Update like this:

using UnityEngine;
using System.Collections;

public class CursorLock : MonoBehaviour {

	public bool cursorLocked;

	void Start () {
		Cursor.lockState = CursorLockMode.None;
		Cursor.visible = true;
	
	}

	void Update () {
		bool cursorState;

		CursorCheck cursorCheck = new CursorCheck ();
		cursorState = cursorCheck.CursorCheck (cursorLocked);
		if (cursorState) {
			Cursor.lockState = CursorLockMode.Locked;
		} else {
			Cursor.lockState = CursorLockMode.None;
		}
	
	}

	 bool CursorCheck (bool cursorLocked) {
		
		if (Input.GetKey (KeyCode.F)) {
			cursorLocked = true;
		} else {
			cursorLocked = false;
		}
		return cursorLocked;
	}
}

But all that did was give me this error:

“Assets/Scripts/CursorLock.cs(17,17): error CS0118: ‘CursorLock.CursorCheck(bool)’ is a ‘method’ but a ‘type’ was expected”

Maybe I’m using return methods wrong? Any help is appreciated!

using UnityEngine;
using System.Collections;

 public class CursorLock : MonoBehaviour {
 
     public bool cursorLocked;
 
     void Start () {
         cursorLocked = false;
         Cursor.visible = true;
     
     }
 
     void Update () 
{
         if (Input.GetKey (KeyCode.F)) 
        {
             cursorLocked = true;
         } 
        else
        {
             cursorLocked = false;
         }

         if (cursorLocked) {
             Cursor.lockState = CursorLockMode.Locked;
         } else {
             Cursor.lockState = CursorLockMode.None;
         }
     
   }
 
 }