- Home /
Function GetButton only returning once?
I'm trying to use Input.GetButton() to have my player jump however it seems that this button is only returning once per run. I'm not sure why this would be doing that below is the code which is fairly simple.
Also if it helps Jump is looking at the Xbox Controllers Joystick Button 0 which is A.
if (Input.GetButton("Jump"))
{
Jump();
}
Not enough info. In what function is the code? Also, you'd want to use GetButtonDown and not GetButton.
Answer by CodeMasterMike · Oct 09, 2012 at 06:55 AM
I'm not sure, but I think that the GetButtonDown/GetButtonUp only fires once per inut. So it doesn't check if the button is pressed down all the time or not.
What you can use instead is the GetAxis() function, which normally has a value between -1 and 1 (0 being not pressed at all). The jump, by default, goes between 1 and 0.
This means that it will react as long as you have the button pressed down, unlike the GetButton function. So you can do something like this:
if(Input.GetAxis("Jump") != 0)
{
Jump();
}
GetButton does check every frame... As @Eric5h5 mentions - it's probably not what the OP wants though, there must be some other logic problem in code we can't see.
Answer by Sinron · Oct 09, 2012 at 04:07 PM
Actually you are correct in stating that it does check every frame. After a few more hours and the simplest bug checking method i discovered the problem was in the logic of my code. All i had to do to see if it was the button or other code was Print("Button Pressed"). After doing so i discovered my error was in multiplying the power in the vectors Y force by Time.DeltaTime in this function. Thanks for the help though it's my fault for not trying the print debug method right off the bat.