Search Unity

Input.GetAxis("Mouse X") doesn't work

Discussion in 'Editor & General Support' started by gautamnarain, Jan 19, 2012.

  1. gautamnarain

    gautamnarain

    Joined:
    Jan 19, 2012
    Posts:
    5
    I have a script which has float x = Input.GetAxis("Mouse X"); But for some reason I always get x to be 0. Its like mouse movement does not even happen. Is there something specific that needs to be done so that mouse input information can be obtained.

    I tried searching online but it doesn't seem like there is any setting which needs to be done to enable mouse movement information to be captured.

    Additionally this is with a regular mouse and keyboard on a laptop.

    Thanks
     
    Last edited: Jan 19, 2012
  2. MADmarine

    MADmarine

    Joined:
    Aug 31, 2010
    Posts:
    627
    Just to make sure, you're not expecting the axis to return the pixel value position of the mouse are you? The axis reading will show the change in position from the last frame, so when the mouse isn't moving it will be 0. To get the position you can use Input.mousePosition.x.

    If you do want to get the change in value, check your settings in Edit > Project Settings > Input, and make sure "Mouse X" is set to use mouse movement and that the sensitivity is above 0.

    A final thing if all else fails, is where that line of code is being executed, is it in Update() in a script and game object that are active?
     
  3. gautamnarain

    gautamnarain

    Joined:
    Jan 19, 2012
    Posts:
    5
    No - I was looking for a delta movement for orienting the character in the way it wants to move. Thanks for the help. I managed to get it working.
     
  4. Juan

    Juan

    Joined:
    May 21, 2009
    Posts:
    142