Unity Community


Results 1 to 7 of 7

  1. Posts
    8

    Lock mouse to CENTER of screen

    Hey guys, as the title suggests I wish to know how to lock the cursor position to the center of the screen.

    Screen.lockCursor doesnt seem to be what I'm after as this hides the cursor (good) and restricts it from leaving the game screen, but i need something that also LOCKS the mouse in the center of the screen.

    Even if there was a way for me to reset the mouse cursor every frame??

    Basically I'm doing a 3rd person shooter with a GUI crosshair, but I want to use onMouseDown on my enemies. So I need my cursor to sit where my crosshair is to make aiming accurate.

    Thanks in advanced.
    Jace


  2. Posts
    8
    actually it seems lockCursor DOES lock the mouse.

    However for somereason it isn't locking it in the middle of the screen, its locking the cursor at some arbitrary position above and to the left of the center.

    Any ideas about why it could be doing that???

    Jace


  3. Posts
    8
    grr now it IS locking in the center of the screen sometimes and other times it is off at that same random position (Up and to the left of the center of the screen)


  4. Posts
    562
    search the forum " Custom cursor or check http://www.unifycommunity.com/wiki/i...tom_2D_Pointer

    should point you to what you need and more

    or lock the cursor and use a game object with a custom texture of cross hair and attach to the camera as a child, something like that.
    MantaRay Interactive
    Video Games For All Ages
    www.mantarayinteractive.net


  5. Posts
    1
    Pardon the necromancy =)

    For prototyping I use this:

    function Update () {
    Screen.lockCursor = true;
    Screen.lockCursor = false;
    }

    Screen.lockCursor moves the pointer to the center of the screen, so it does exactly what the OP suggested - resets the cursor every frame.

    You could also use a MouseMove event for example

    Not very clean but it does the job, you retain OnMouseDown functionality, the cursor remains visible.


  6. Posts
    2
    if your using C#
    i use this for setting the value to true or false if paused

    public static bool paused = false;

    void Start()
    {
    Time.timeScale = 1;
    }
    void Update ()
    {

    Screen.lockCursor = true;
    if(paused ==false)
    Screen.lockCursor = false;

    if(Input.GetKeyDown(KeyCode.Escape) && paused == false)
    {
    paused = true;
    Time.timeScale = 0;
    }
    else if(Input.GetKeyDown(KeyCode.Escape) && paused == true)
    {
    paused = false;
    Time.timeScale = 1;
    }
    }


  7. Posts
    1
    Nice. Good quick fix!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •