I have a player with a character controller component.

When the player is generally interacting with the UI I would like to stop the character and camera controller and show the cursor to the player in order to (e.g select a weapon) and when they're done I would like it to switch back.

How do I address this issue?

  • \$\begingroup\$ So you just need the mouse cursor to show up when selecting a weapon and then disappear, am i correct? Also which language are you using? \$\endgroup\$ – Valamorde Jan 27 '18 at 11:16

As per my understanding your player has a First Person Character controller Component. You'd need a script sitting on some GameObject of your preference and in that script you should follow this logic:

public ui_gameobject; //Attach this in the Inspector

//Check if UI is being displayed and handle the cursor
void DetectUIandHandleCursor(){
         Cursor.visible = true;
         Cursor.lockState = CursorLockMode.None;
         Cursor.visible = false;
         Cursor.lockState = CursorLockMode.Locked;     

I suppose you already have a script managing your UI elements (meaning switch them on/off), so the previous snippet should check when you are displaying it and show or hide the cursor accordingly.


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.