Having a little issue with a script ... A script to hide the mouse, ("Parsing Error" and "Unexpected Symbol 'else' ") The script works now :)

I wrote a script to hide the mouse in my game (FPS Game) and when I press left control I want the mouse to appear and it would be nice if my screen could lock. This is my script, it looks fine to me but I get a Parsing Error and a Unexpected Symbol ‘else’. Thanks for the help and I sorry for any grammar errors, I’m French ! I’m also new to scripting, thanks for understanding.

using UnityEngine;
using System.Collections;

public class MouseHide : MonoBehaviour {

	void Start (){
		Screen.showCursor = false;
		Screen.lockCursor = true;
	}

	void Update () { 
		{
		if (Input.GetKey(KeyCode.LeftControl))
			Screen.showCursor = true;
			Screen.lockCursor = false;
		}
		else
		{
			Screen.showCursor = false;
			Screen.lockCursor = true;
		}
	}
}

Inside your Update()

 void Update () { 
        if (Input.GetKey(KeyCode.LeftControl))
{
            Screen.showCursor = true;
            Screen.lockCursor = false;
        }
        else
        {
            Screen.showCursor = false;
            Screen.lockCursor = true;
        }
    }

Look at:

void Update () { 
    {
    if (Input.GetKey(KeyCode.LeftControl))

There’s two left braces after Update(), and no brace after the if-block. That’s what’s causing the error.

void Update () {
{ <— EXTRA BRACE :slight_smile:
if (Input.GetKey(KeyCode.LeftControl))
Screen.showCursor = true;
Screen.lockCursor = false;
}
else
{
Screen.showCursor = false;
Screen.lockCursor = true;
}
}

Regards,