Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved Get continuous Mouse ScrollWheel

Discussion in 'Scripting' started by sstrong, Nov 25, 2020.

  1. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,258
    In there Unity (legacy) Input System there are a few ways to get mouse scroll wheel input. For example:
    Code (CSharp):
    1. Input.GetAxis("Mouse ScrollWheel")
    2. Input.GetAxisRaw("Mouse ScrollWheel") // Unsmoothed data
    3. Input.mouseScrollDelta.y
    Each return float values of -1 to 1. GetAxis and GetAxisRaw may return values less than +/- 1 if sensitivity is less than 1.

    I've tried Unity 2018.4 and 2020.1 with different Window 10 devices and mice and only get a single value when the mouse wheel is being scrolled.

    How do I get a continuous stream of non-zero values while the scroll wheel is being moved?
     
  2. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    372
    Hi, sorry but I'm not getting what you're asking for here. Are you not getting any value on a windows 10 system, or what?

    All of the calls in your example code return a single value, and they only return non-zero values when the wheel is turned. So, I'm not sure why you make those points, because that is the way those calls behave. Do you want to alter those behaviors, somehow?

    If you want a "stream" - if I understand what you mean - put the given call in an Update loop. You can couch your code in something like this so that you only respond to non-zero values:

    Code (CSharp):
    1. float ScrollWheelChange = Input.GetAxis( "Mouse ScrollWheel" );
    2.             if( Mathf.Abs( ScrollWheelChange ) > 0 ) {
     
  3. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,258
    I worked it out. The scroll wheel doesn't return a value every frame that the scroll wheel is moving. This is different from how something like GetKey works or other input axis. I had to use a decaying value concept to simulate a similar behaviour.
     
    Maloke likes this.