Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TheGeneralBenLee · May 20, 2021 at 07:02 PM · controllerbeginnerpackageinput managerinput.getbutton

using new input system, how do I get a result similar to Input.GetButtonDown?

I am currently using the new input system and almost everything is set up, except the mouse button. I use the InputActionReference called rightClickControl and this is all set up correctly using OnEnable() and OnDisable().

The issue I am having is that when I click my mouse, two inputs are registered, one on the mouse down and one on the mouse release. If i use the below code it works, but if i change triggered to started (unity docs say started and performed both register once, and triggered does it twice for buttons) i get an error, and i am trying to get all of this set up before i move on to learning anything to do with delegates and events. i wanna keep my game as readable as possible without jumping into the deep end with delegates and events.

Is there any way i can fix this? is there a property of InputActionReference.action that i am missing? thank you in advance, this community is flawless and so helpful. please bear in mind that my other controls (movement etc) work using this system and i don't want to scrap the work i put in to making it work.

 public void testFunction()
 {
     if (rightClickControl.action.triggered)
     {
         Debug.Log("Mouse Button Down");
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Razputin · May 21, 2021 at 01:27 AM

set a bool true on click false on cancel click

mine is with events and yours isn't but it should still be roughly the same, can you post the error you're getting?

     private void Update()
     {
         if (isFiring)
         {
             Firing();
         }
     }
 
  public void Fire(InputAction.CallbackContext value)
         {
             if (value.started)
             {
                 isFiring = true;
             }
             if(value.canceled)
             {
                 isFiring = false;
             }
         }


         public void Firing()
        {
 //fire the gun
         }
     }









Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TheGeneralBenLee · May 21, 2021 at 08:01 AM 0
Share

I can't check this on my system until I return to my laptop in 8 hours but by reading it, am I right in thinking that this is a constant input whenever it's true as opposed to a one time input? Just trying to achieve a one time input if this is possible. Thank you for your answer nonetheless it's very helpful still

avatar image Razputin TheGeneralBenLee · May 21, 2021 at 11:10 AM 0
Share

oops I was thinking getbutton,

get button down would be to just put the method in value.started

              if (value.started)
              {
                  Firing();
              }
 
avatar image TheGeneralBenLee · May 21, 2021 at 07:03 PM 0
Share

It doesn't seem to work for some reason. when i change .triggered to .started, here is the error i get:

The event 'InputAction.started' can only appear on the left hand side of += or -= [Assembly-CSharp]csharp(CS0079)

Sorry to take up so much of your time so far, something just isn't exactly clicking for me.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

139 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can GetKey/GetKeyDown/GetKeyUp all return true in the same frame? 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Read analog stick input without using the Input Manager 1 Answer

where is package manager Unity 2020.3.10f1,package manager is missing Unity 2020.3.10f1 0 Answers

Get x/y joystick axis from hatswitch? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges