Search Unity

Resolved Mouse ScrollWheel with 1DAxis

Discussion in 'Input System' started by sstrong, Nov 19, 2020.

  1. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,252
    I'm trying to get the scrollwheel to work with 1DAxis. I can get it to work by setting "Which Side Wins" in the editor but can't work out to do it in code.

    Code (CSharp):
    1. action = UnityEngine.InputSystem.InputActionSetupExtensions.AddAction(
    2.             actionMap, "ZoomLook", UnityEngine.InputSystem.InputActionType.Value, null, null, null, null, "Axis");
    3. if (action != null)
    4. {
    5.     UnityEngine.InputSystem.InputActionSetupExtensions.AddCompositeBinding(action, "1DAxis")
    6.          .With("Positive", "<Keyboard>/rightBracket", "Keyboard&Mouse")
    7.          .With("Negative", "<Keyboard>/leftBracket", "Keyboard&Mouse");
    8.  
    9.     UnityEngine.InputSystem.InputActionSetupExtensions.AddCompositeBinding(action, "1DAxis")
    10.         .With("Positive", "<Gamepad>/dpad/up", "Gamepad")
    11.         .With("Negative", "<Gamepad>/dpad/down", "Gamepad");
    12.  
    13.     UnityEngine.InputSystem.InputActionSetupExtensions.AddCompositeBinding(action, "1DAxis")
    14.          .With("Positive", "<Mouse>/scroll/y", "Keyboard&Mouse")
    15.          .With("Negative", "<Mouse>/scroll/y", "Keyboard&Mouse");
    16.  
    17. }

    I'm using the verified 1.0.0 in U2019.3. For some reason, I'm not sure why, if I leave "Which Side Wins" to neither it does nothing.

    So, how can I set "Which Side Wins" in an editor script?
     
  2. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,252
    Found the answer in the v1.1 preview-2 documentation.
    Code (CSharp):
    1. UnityEngine.InputSystem.InputActionSetupExtensions.AddCompositeBinding(action, "1DAxis(whichSideWins=1)")
    2.      .With("Positive", "<Mouse>/scroll/y", "Keyboard&Mouse")
    3.      .With("Negative", "<Mouse>/scroll/y", "Keyboard&Mouse");