Search Unity

Locked cursor but visible?

Discussion in 'Getting Started' started by jeroen1205, Jan 13, 2022.

  1. jeroen1205

    jeroen1205

    Joined:
    Dec 7, 2016
    Posts:
    4
    Hi,

    I'm working on the game mechanics of a first-person adventure game. What I want to achieve is something like this:

    - cursor is locked in middle with a default icon
    - cursor hovers item in scene which is interactable, cursor changes to flashing cursor
    - cursor returns to default when leaving

    Locking the cursor was easy, by setting the lockState to "Locked". But this always hides the cursor regardless of the "visible" property. Changing state when an item is hovered was also very easy, I'm just using a collider on the object and using the MouseEnter and MouseExit events.

    However, how do I work around the issue of the cursor not being visible? Is there another way to keep my mouse centered while displaying the cursor? Or should I create a HUD and "fake" a cursor by putting an icon on the centre?

    What is accepted "best practice" for this scenario?
     
    umbrella-crash likes this.
  2. umbrella-crash

    umbrella-crash

    Joined:
    Mar 3, 2022
    Posts:
    20
    Did you ever find an answer to this question? I want to do much the same thing. Thanks
     
  3. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    You probably wouldn't want the actual mouse cursor visible during lock, as depending on platform it may move away from center by the movement delta each frame and then snap back (which of course doesn't look good). I'd say for something like a crosshair, the HUD with "fake" cursor is the solution.