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!