I have a player with a third person character controller component. I have a problem with the cursor lock: it hides the cursor so I cannot click UI buttons.

protected virtual void CharacterInit()
    cc = GetComponent<vThirdPersonController>();
    if (cc != null)

    tpCamera = FindObjectOfType<vThirdPersonCamera>();
    if (tpCamera) tpCamera.SetMainTarget(this.transform);
    Cursor.visible = false;
    Cursor.lockState = CursorLockMode.Locked;
  • \$\begingroup\$ It's unclear to me why you would lock and hide the cursor if you want to use the cursor to click on UI buttons. Have you considered not locking the cursor instead? \$\endgroup\$ – DMGregory Jul 7 '20 at 12:49

i think you mean mouse cursor. that only locks you cursor not hiding it. to hide you only need:


remember best approach to use mouse cursor is to hide it in the game and set a sign in game ui and always give mouse position to it.

if you want to disable and enable mouse controll you can simply define a boolean variable.

bool UseCursor;
void Update(){
if(!useCursor) return;
// use mouse login here

To be able to see the mouse cursor:

Cursor.visible = true;

To be able to click UI and unlock the mouse cursor:

Cursor.lockState = CursorLockMode.None;

Make sure to call these after you call the function in your post, otherwise they won't work.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.