- Home /
(Linux Player) Why does Input.GetButtonDown return true every frame?
I've recently been testing my game on Linux and noticed that Input.GetButtonDown("Submit") button on the new UI seemed to be true every frame that the button was held.
To test further, I created a new project with one scene and the following script:
using UnityEngine;
public class TestInput : MonoBehaviour
{
int mCount = 0;
void Update()
{
if (Input.GetButtonDown("Submit"))
{
mCount++;
}
}
void OnGUI()
{
GUILayout.Label("Count: " + mCount.ToString());
}
}
I built for linux and tested on Lubuntu 14.10 and Ubuntu 14.04 (both fully updated) with the same result - GetButtonDown is functioning like GetButton.
This is using a controller/joystick to test. I have tried two - a generic HID and an Xbox 360 controller. Pressing Enter on the keyboard works as expected (only triggers once per press). I have tried the jstest utility in Linux and it reports down events only once as you would expect.
In the editor and build for Windows it functions normally (with the same controllers).
I am using Unity 4.6.0f3.
Answer by Schubkraft · Jan 07, 2015 at 09:50 AM
This is indeed a bug and you can follow it at http://issuetracker.unity3d.com/issues/input-dot-getbuttondown-returns-true-for-as-long-as-it-is-held
Answer by WillNode · Dec 29, 2014 at 07:07 AM
if this bugs are always appear, you need to report this problem to Unity.
i don't know how to solve this problem since I don't have Linux OS to solve it, but there is work-around to solve this problem, you need to add little more code.
private bool m_btnInUse = false;
void Update()
{
if( Input.GetButtonDown("Submit")) {
if(m_btnInUse == false) {
// Call your event function here.
m_btnInUse = true;
}
}
if(!Input.GetButtonDown("Submit"))
m_btnInUse = false;
}
Your answer
Follow this Question
Related Questions
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
Linux Standalone and Japanese 0 Answers
each character doubled in inputfield in build but not editor on ubuntu 16.04 2 Answers
When I try to bind a key in the new input system bind dropdown, nothing shows (linux) 2 Answers