Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Stolken · Jul 18, 2011 at 05:49 AM · 2dspritequaternionlerp

Postive and Negative Button Binding

I was wondering, it is possible to bind positive and negative buttons as a command. Like with GetButtonDown. I have a script where if you hit left or right certain animations play, but how do I rebind it so that players can re-assign these keys?

Comment
Add comment · Show 1
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 Stolken · Jul 18, 2011 at 07:03 AM 0
Share

I know there is a way to try this, I ran the game myself seeing if changing those keys would work. Nope, didn't.

3 Replies

· Add your reply
  • Sort: 
avatar image
8

Answer by Democide · Jul 07, 2014 at 09:22 AM

What you can do is get the button and then check for the corresponding axis, like so:

 if (Input.GetButtonDown("Horizontal") && Input.GetAxisRaw("Horizontal") > 0) {
     // Move to the right
 } 
 else if (Input.GetButtonDown("Horizontal") && Input.GetAxisRaw("Horizontal") < 0) {
     // Move to the left
 }

Also be aware that the axis is set to SNAP. This means a change of direction instantly sets the axis to 0.

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 RocketFriday · Sep 24, 2017 at 12:28 PM 0
Share

Thank you! Works great! :D

avatar image watercat · Dec 31, 2017 at 12:48 PM 0
Share

I have a character and I want to jump with ("vertical") Positive if with that code will work?

avatar image watercat · Dec 31, 2017 at 01:28 PM 0
Share

this code worck bat i have 1 problem

m_Jump = CrossPlatformInput$$anonymous$$anager.GetButtonDown("p1 Jamp");

if i change this to m_Jump = CrossPlatformInput$$anonymous$$anager.GetButton("p1 Vertical") && Input.GetAxisRaw("p1 Vertical") > 0; the jamp is no the same this coede is the Platformer2DUserControl

avatar image
1

Answer by fschneider · Jul 07, 2014 at 09:25 AM

The documentation linked above is saying you should use

  value = Input.GetAxis ("Horizontal"); 

and then check whether the value is above or below zero.

Comment
Add comment · Show 1 · 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 Democide · Jul 07, 2014 at 09:26 AM 1
Share

Well that works, but it fires EVERY FRA$$anonymous$$$$anonymous$$ GetButtonDown only fires in the frame that the button was pressed. So these are used for different cases.

avatar image
0

Answer by MasterBLB · Jul 18, 2011 at 07:15 AM

In the doc for GetKeyDown there is mentioned to use GetButton instead,as it allows binding,while GetKeyDown works on enum: http://unity3d.com/support/documentation/ScriptReference/Input.GetKeyDown.html

Comment
Add comment · Show 7 · 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 Stolken · Jul 18, 2011 at 07:18 AM 0
Share

So how would I make the command for GetButtonDown?

I just tried GetButtonDown("right") and that sure didn't work.

avatar image MasterBLB · Jul 18, 2011 at 07:23 AM 0
Share

Well,try to run your project on PC,and when resolution∈put dialog shows switch tab to input and see what bind is for "right",then press that key and see if it works.

I see there is no something like "right",but the control name is "Horizontal(+)"

avatar image Stolken · Jul 18, 2011 at 07:31 AM 0
Share

I did both GetButtonDown("Horizontal(+)") and GetAxis("Horizontal(+)") and neither worked.

avatar image MasterBLB · Jul 18, 2011 at 07:36 AM 0
Share

Hmm..and did you add Input$$anonymous$$anager component to a mesh containing your script?The doc is not clear about it,but I bet it's necessary in order to work

http://unity3d.com/support/documentation/$$anonymous$$anual/Input.html

avatar image Democide · Jul 07, 2014 at 01:58 PM 1
Share

See my solution below: The issue is: GetButtonDown("Horizontal") fires for both the positive and the negative button. You need to do this but also check for the value of the axis to figure out if you're pressing the positive or negative button for that axis. Then you can use that to control your game. I just did it and it worked.

Show more comments

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

8 People are following this question.

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

Related Questions

Quaternion Rotate Towards Y Value 1 Answer

2D Sprite leaves a trail when moving diagonally 1 Answer

Moving 2D sprite along a path 0 Answers

How do I scale a 2D sprite over time? 2 Answers

apply a modified rotation based on another objects' rotation 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