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 How do I transfer Input.GetMouseButton() to the new input system?

Discussion in 'Input System' started by alexreynlds_, Dec 19, 2022.

  1. alexreynlds_

    alexreynlds_

    Joined:
    Apr 30, 2020
    Posts:
    2
    Hi!
    I was watching a tutorial about creating text boxes and part if it included the line:
    Code (CSharp):
    1. yield return new WaitUntil(() => Input.GetMouseButton(0));
    which works fine for clicking with a mouse however it doesnt work on controller so does anyone know a way I could make it work with that?

    Thank you so much
     
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,903
    There is a workaround method that works as a transition stop-gap while you rework your logic to the new Input System way of doing things.

    Code (csharp):
    1.  
    2. Mouse.current.leftButton.isPressed // equivalent to Input.GetMouseButton(0)
    3. Mouse.current.leftButton.wasPressedThisFrame // equivalent to Input.GetMouseButtonDown(0)
    4. Mouse.current.position.x // equivalent to Input.mousePosition
    5.  
    Look up the Mouse and Keyboard classes to see more items available. However, your goal should be to move away from spot-checking immediate values from specific hardware like Mouse or Keyboard, and to move toward the event driven device-agnostic system using Input System Action Maps.

    As for Controllers, that's what the new Input System is to help you cover. You will want to go through an Input System tutorial to see more about how to set up a joystick.
     
    alexreynlds_ likes this.
  3. alexreynlds_

    alexreynlds_

    Joined:
    Apr 30, 2020
    Posts:
    2
    Brilliant! This worked like a charm for now but I'll start looking into a proper system right away, thank you for youre help!