Search Unity

Unity's new input system

Discussion in 'Scripting' started by Robster95, Jan 20, 2021.

  1. Robster95

    Robster95

    Joined:
    Jul 3, 2019
    Posts:
    154
    I am having some trouble with the new Unity input system. I have been working along with some friends and I don't know how I feel about it.

    We were trying to make a gun shoot when the play pushes in a controllers right trigger but cant get the bullets to shoot when you push in the trigger only when you meet the time required for the hold interaction. I also am using a tap interaction and tried it with a press but it only let one of them work at a time. ( either hold or tap/press at the same time)

    I feel like the old input system is so much easier to work with but feel in order to get local multiplayer or just a controller to work "easier" I would need to learn about the new input system.

    How does everyone else feel about the input system? Is there a way to learn it easier since the documentation isn't the best or videos that have explained it well? Everything I saw covers the basics but never shows making a more serious game or going over other methods/ using interactions
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Definitely a bit of a higher learning curve but also a lot more capable and scriptable in general. It really depends on the project I'm working on. If it's local multiplayer, I would definitely use the new input system for all the events and callbacks you can get related to input devices.
     
    Robster95 likes this.
  3. Robster95

    Robster95

    Joined:
    Jul 3, 2019
    Posts:
    154
    I'm working on a single player top down shooter type game.

    I'm having the problem where if I pull the right trigger to shoot it works but if I hold it it wont continuously shoot or call the code. It only checks to see if it meets the holding time requirement and shoots once. Is there a way to make it so I can start shooting the second I pull the trigger so it doesn't seem like there's a shoot delay and also able to make it keep calling the code so a weapon like a machine gun can fire?
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Sounds like you're using the
    OnPerformed
    callback. First of all if you don't want a delay, remove the hold action entirely.

    Second, if you want it to be continuous, you could set a bool variable to true when you get the OnPerformed callback, and set it back to false when you get the OnCancelled callback. Then you just check if your bool is true and fire.

    Alternatively, instead of using the events, you could just call
    GetValue<float>()
    on the InputAction in Update. Then it will behave just like how the old Input.GetButton() stuff worked.
     
    renatodeoliveirarj and Robster95 like this.
  5. Robster95

    Robster95

    Joined:
    Jul 3, 2019
    Posts:
    154
    That's what I was thinking of doing, setting a bool and checking it. If I were to do that, I'm guessing I will put it in the update() and have it continuously check for the bool correct? Or will it be better to have it in it's own function and called at a certain time?

    Also can you explain how I will do the GetValue<float>()? I'm not to sure on how to go about that technique.