How do I make the mouse centered in Fps?

Can someone help me with how do I use the cursor.lock script provided by unity. I created another script component on the camera and paste the code there but it didnt work.

By not working, do you mean that the mouse is centered in the middle of the screen but is still visible? If so, you need to use “Screen.showCursor”.

#Pragma Strict

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

Function Update ()
{
if(Input.GetKeyDown(KeyCode.Escape))
{
Screen.lockCursor = false;
Screen.showCursor = true;
}
if((Input.OnMouseDown) || (Input.GetKeyDown(KeyCode.L)))
{
Screen.lockCursor = true;
Screen.showCursor = false;
}
}

This will hide the mouse and lock it on start, or whenever you left click/press the L key. If you want to have the mouse be visible, but still locked, just delete the lines “Screen.showCursor = True” from the script. Good luck!