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. Dismiss Notice

Standard inputs for quick scripting

Discussion in 'Input System' started by PeteSmalls, May 12, 2020.

  1. PeteSmalls

    PeteSmalls

    Joined:
    Apr 29, 2020
    Posts:
    11
    Hi Guys,
    Total disclosure - I am new to Unity.
    That said - I have been learning scripting by smashing together quick experiments to learn and test concepts.
    It seems in the "old world" you could create a brand new project, do nothing special, open a script, type OnMouseDown and Unity would be listening for a mousedown to do whatever I put in that method (Say - a simple Debug).
    Similar for KeyDown or even Input.MousePosition.
    Can jump in, a shoot a ray with 3 lines of code in an update method.
    This makes it SUPER easy to get something working quickly.

    Does the new Input System have this type of quick win or do all inputs need to be previously defined in the input manager and then enabled in each class and/or assigned as a "PlayerInput" (even though sometimes it has nothing to do with a "player"?
    And follow on:
    If not - what is an example to read mouseposition (for example).
    If so - is there a generic inputs map that contains ALL the keys and mouse inputs so we can just toss that in to get the functionality described above with minimal setup time?

    I guess my question is...
    What is the fastest(least setup time) way to go from opening a new project to me being able to have an object follow my mousepostion and watch for mousedown to smash together test scripts? :)
     
  2. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    There is a zero-setup path for reading device input directly but not yet for actions.

    Code (CSharp):
    1. void Update()
    2. {
    3.     // Read mouse position.
    4.     var pos = Mouse.current.position.ReadValue();
    5. }
    6.  
    1. Add PlayerInput
    2. Click "Create Actions..." and hit enter.
    This will set up a PlayerInput with "Send Messages" behavior and a default set of actions (similar to what the old input manager has) that you can customize. You can respond to the action messages with OnXXX methods (with XXX being the action names).
     
  3. PeteSmalls

    PeteSmalls

    Joined:
    Apr 29, 2020
    Posts:
    11
    Thanks! Is is super helpful!