0
\$\begingroup\$

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)
         cc.Init();

    tpCamera = FindObjectOfType<vThirdPersonCamera>();
    if (tpCamera) tpCamera.SetMainTarget(this.transform);
           
    
    Cursor.visible = false;
    Cursor.lockState = CursorLockMode.Locked;
}
\$\endgroup\$
1
  • \$\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
0
\$\begingroup\$

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

Cursor.visible=false;

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
}
\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$

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.