Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
3
Question by Nalincah · Feb 10, 2020 at 08:50 PM · input

Input System - Detect if key for action was pressed or released

I have a simple setup with one Map and one Action, lets say "Jump" with a binding to "Space".

Now I want to start a charge up animation on "Press" and do the actual jump on "Release" so I a trigger behavior Press And Release. I added an Subscriber to my Event but I can't find a way to determine if I am currently in the "Press" or in the "Release" state.

Or should I add two Actions? "Charge" and "Jump". One with the "Press Only" behavior and the other with "Release Only"

Comment
Add comment · Show 5
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 ShadyProductions · Feb 10, 2020 at 09:11 PM 0
Share

Can you show some code? Like I have no idea what you are talking about, which event? Are you using some kind of asset?

avatar image AltaNox ShadyProductions · Feb 10, 2020 at 09:39 PM 0
Share

He is talking about the new Input System. And that event is probably provided through the PlayerInput component with an Input Actions asset assigned.


I agree with you, he should show some code. The new Input System is fairly complex, with multiple ways of achieving the same thing. It would be very hard to help him without taking a look at the code.

avatar image Nalincah ShadyProductions · Feb 14, 2020 at 08:08 PM 0
Share

Here you can see the Input Actions with "Press and Release" and the Component

Input Actions Component

And from my Player-Script

  public void Shoot(InputAction.CallbackContext context)
     {
         Debug.Log(context.valueType + " - " + context.action + " - " + context.control + " - " +
                   context.started + " - " + context.performed + " - " + context.canceled + " - phase: " + 
                   context.phase + " - " + context.interaction);
     }
 
     public void $$anonymous$$ove(InputAction.CallbackContext context)
     {
         Debug.Log("$$anonymous$$ove " + context.ReadValue<float>());
     }

avatar image Nalincah · Feb 10, 2020 at 09:40 PM 0
Share

I use the new Unity Input system https://blogs.unity3d.com/2019/10/14/introducing-the-new-input-system/

avatar image AltaNox Nalincah · Feb 10, 2020 at 09:42 PM 0
Share

If you don't show your code, we won't be able to help you

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by rekatha · Jul 09, 2020 at 06:54 AM

this is what you need to do when choose Press And Release. First Add Player Input component. And then set Player Input behavior to Invoke Unity Event. Add function from your script, let say OnJump This is logic for press and release button:

 //Callback for "Space" button
 public void OnJump(InputAction.CallbackContext context)
 {
     if (context.started)
     {
         //button is press
     }
     else if (context.cancelled)
     {
         //button is released
     }
 }

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 UrsinhoMalvado · Dec 29, 2021 at 02:23 PM 0
Share

@rekatha something change since you post this? In my case "context.canceled" is only called after I turn off the game (inside Unity). I'm using Press[Touchscreen] as binding, and when I lift my finger "context.canceled" isn't called (tested on my phone).

avatar image tacman1123 · May 16 at 02:47 PM 0
Share

Typo: cancelled should be canceled

avatar image tacman1123 · May 16 at 02:48 PM 0
Share

Typo: cancelled should be canceled

avatar image
0

Answer by edthered1009 · Feb 13, 2020 at 01:43 AM

You can have a single action (for example "Jump"), and do this: if (GetButtonDown("Jump")) { //Charge } if (GetButtonUp("Jump")) { //Jump }

Hope this helps!

Comment
Add comment · 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

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

148 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

Input keycode string not working 2 Answers

New Input axis with Numpad Keys 2 Answers

how can I assign and use different controller schemes for a single keyboard? 0 Answers

GuiTexture as crosshair as scroll over to activate things 1 Answer


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