- Home /
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;
}
}
}
I replace my show/hide mouse script with this and it worked flawlessly. Are you sure it is not a different script giving you errors, and did you remember to press CRTL + S to save your changes?
Yes, I fix the Parsing Error thanks to B$$anonymous$$ayne but I still get the Unexpected symbol 'else' error ... This is my code now :
using UnityEngine;
using System.Collections;
public class $$anonymous$$ouseHide : $$anonymous$$onoBehaviour {
void Start (){
Screen.showCursor = false;
Screen.lockCursor = true;
}
void Update () {
{
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftControl))
Screen.showCursor = true;
Screen.lockCursor = false;
}
else
{
Screen.showCursor = false;
Screen.lockCursor = true;
}
}
Answer by BMayne · Sep 01, 2014 at 04:31 PM
void Update () {
{ <--- EXTRA BRACE :)
if (Input.GetKey(KeyCode.LeftControl))
Screen.showCursor = true;
Screen.lockCursor = false;
}
else
{
Screen.showCursor = false;
Screen.lockCursor = true;
}
}
Regards,
void Update () {
{ <--- EXTRA BRACE :)
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftControl))
{ <---- $$anonymous$$ISSING BRACE
Screen.showCursor = true;
Screen.lockCursor = false;
}<-- THAT WOULD CLOSE THE $$anonymous$$ETHOD without the other.. in the correct position.
else
{
Screen.showCursor = false;
Screen.lockCursor = true;
}
}
Thanks ! It works now ! Now I don't accidentally press any buttons when moving the camera.
Answer by Baste · Sep 01, 2014 at 11:06 PM
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.