Cursor Locks/Hides but Will Not Reappear?

I am using two scripts to control the locking and unlocking of the cursor. Both are placed on the default unity First Person Controller and are in Javascript.

This script called “Mouse_Lock” hides and locks the cursor like intended.


      function Update () {
         Screen.lockCursor = true;
         }

This seperate script disables and enables the above script on a keypress.


function Update () {
if (Input.GetKeyUp("p")) {
    var mouseLock = GetComponent.< Mouse_Lock>();
    mouseLock.enabled = !mouseLock.enabled;
    Screen.showCursor = true;
    }
}

During runtime the cursor is hidden and locked to the center of the screen initially. When I press “p” the second script deactivates the first, which I confirmed by seeing it uncheck in the inspector. However the cursor never reappears for me to be able to click anything. It will allow me to click outside the game on the editor whereas the cursor reappears, and will allow me to click in game again untill it disappears from using the second script to toggle lockCursor on. I have tried other scripts with these functions together in one script but the cursor never reappears when toggling off lockCursor.

Im very new to scripting and I’m sure its something very obvious that I’m missing. Any help would be greatly appreciated. Thanks!

You don’t really need to seperate this one. I only do that if the scripts are trying to accomplish different tasks.

Try this…

function Start ()

{ 

	Screen.lockCursor = true; // Start the game with the cursor locked or not (true or false)

  

}





function Update () {

		

	if(Screen.lockCursor == false && Input.GetKeyUp("p"))

	{

		Screen.lockCursor = true;

	}

	else if (Input.GetKeyUp("p"))

	{

		Screen.lockCursor = false;

	}



}

T27M - YOU ARE GOOOOOOOOOOOOOOD TNX 2 YOU I FIX MY PROBLEM TO . I WASTE ALL DAY BUTH YOUR POST MAKE MY EAVNING BETER TNX ONE MORE TIME .,YOU ARE GOOD 2 ME I WASTE ALL DAY TO FIX MY MOUS TNX AND MEGA TNX