Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Locking cursor, setting position.

Discussion in 'Scripting' started by Karmarama, Sep 3, 2011.

  1. Karmarama

    Karmarama

    Joined:
    Jul 11, 2011
    Posts:
    261
    I tried googling and searching around for how to set the cursor position with Screen.lockCursor, and haven't come across any advice other than doing this with C# or boo which requires some other .dll component.

    All I'm wanting to do is set the cursor position to the center of a GUI.Texture, and then locking it there and never allowing it to escape the center, or use something like width/2, height/2.

    Cheers.
     
  2. BlackMantis

    BlackMantis

    Joined:
    Feb 7, 2010
    Posts:
    1,475
    What's the logic behind the GUI texture position.(What are you trying to do) lol.

    Do you want the cursor to be visible or not?

    Is the Gui texture centered or off?
     
  3. Karmarama

    Karmarama

    Joined:
    Jul 11, 2011
    Posts:
    261
    GUI Texture is using pixel inset:
    X/Y = 0
    W/H = 32

    I want the cursor locked, hidden and in the center of the GUI Texture or in the center of the screen (Screen.width/2, Screen.height/2). I'm just unsure how to apply the position to the cursor.
     
    Last edited: Sep 3, 2011
  4. Karmarama

    Karmarama

    Joined:
    Jul 11, 2011
    Posts:
    261
  5. Karmarama

    Karmarama

    Joined:
    Jul 11, 2011
    Posts:
    261
    Bump? =/
     
  6. Karmarama

    Karmarama

    Joined:
    Jul 11, 2011
    Posts:
    261
    Sigh, bump.
     
  7. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
  8. Karmarama

    Karmarama

    Joined:
    Jul 11, 2011
    Posts:
    261
    I know of the command screen.lockcursor.

    What I'm asking is, does screen.lockcursor automatically lock the cursor to the center of the screen regardless of resolution or is there some way for me to control the position of where it locks?

    What if I'm unlocking the cursor for the main menu or on alt tab, and the player clicks back on the game screen, will that re-center the cursor position?
     
  9. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
    The cursor will automatically be hidden, centered on view and made to never leave the view.

    That's fairly unambiguous.
     
  10. Karmarama

    Karmarama

    Joined:
    Jul 11, 2011
    Posts:
    261
    Center aside, then, what of a custom position?