Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Button With One Modifier inside of Vector 2D Composite

Discussion in 'Input System' started by wardler, Aug 17, 2021.

  1. wardler

    wardler

    Joined:
    Jan 25, 2021
    Posts:
    22
    I'm looking for a way to add a Button With One Modifer as another entry for Up inside of this 2D Vector composite.

    What I'm trying to do: Use "W" for Up and use "Mouse Left + Mouse Right" for Up and return normalized Vector2.

    The solution I'm using now is to take both inputs, then break them apart in the script and then add them back together and normalize.

    vector2dcomposite.png vector2dcomposite2.png

    Code (CSharp):
    1.         private void Awake()
    2.         {
    3.             _inputMaster = new InputMaster();
    4.  
    5.             _inputMaster.Player.GrabCamera.started += _ => GrabCamera();
    6.             _inputMaster.Player.GrabPlayer.started += _ => GrabPlayer();
    7.             _inputMaster.Player.GrabCamera.performed += _ => ReleaseCamera();
    8.             _inputMaster.Player.GrabPlayer.performed += _ => ReleasePlayer();
    9.             _inputMaster.Player.Jump.started += _ => _mover.Jump();
    10.             _inputMaster.Player.AutoRun.started += _ => AutoRun();
    11.             _inputMaster.Player.AutoRunCancel.started += _ => AutoRunCancel();
    12.         }
    13.  
    14.         private void Update()
    15.         {
    16.             _mover.Move(GetMovementInput());
    17.         }
    18.  
    19.         private Vector2 GetMovementInput()
    20.         {
    21.             var movementInput = _inputMaster.Player.Movement.ReadValue<Vector2>();
    22.             if ( _isAutoRunning || _isMouseRunning)
    23.             {
    24.                 movementInput.y = 1;
    25.             }
    26.             movementInput = movementInput.normalized;
    27.             return movementInput;
    28.         }
     
    Last edited: Aug 17, 2021