- Home /
uGUI button doesn't work on touch monitor
My app works fine on Android phones or tablets. For some reason, it must run on a touch monitor(OS: Android 8.0), and uGUI button doesn't work on the monitor. To investigate the touch problem, I have made a simple test App. The main scene only has the Camera, one Canvas(includes one Button and three Texts), EventSystem gameobject, and one gameobject for attach the test script.
Here is my test code:
public void OnClickUGUIBtn()
{
nLog1Count++;
textLog01.text = "Log 01 Click " + nLog1Count + " times";
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
nLog2Count++;
textLog02.text = "Log 02 Click " + nLog2Count + " times";
Debug.Log("GetMouseButtonDown");
}
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
nLog3Count++;
textLog03.text = "Log 03 Click " + nLog3Count + " times";
}
}
}
OnClickUGUIBtn() is assigned to "On Click" event of an uGUI button. When tests with Editor, Android phone/tablet, or iPhone, it works correctly. However, when the test app runs on that touch monitor and I click the button --
"Input.GetMouseButtonDown(0)" will be triggerred ONE time (only once).
"Input.touchCount > 0" never becomes true.
"OnClickUGUIBtn()" is never triggered.
After "Input.GetMouseButtonDown(0)" triggered one time, all touch events never happen again. I build the test App with Unity 2019.2.21f1 and 2019.4.3f1 and tried all combinations of Scripting Backend/TargetArchitecture such as IL2CPP with ARMv7 only, IL2CPP with ARMv7/ARM64, Mono with ARMv7/x86,...
All combination got the same result.
HOWEVER, if I use Unity 2017.4.26f1, all touch events work correctly!
Does anybody know what happen? Is it a unity bug?
(Since Unity 2017 and 2019 use different JDK, SDK, and NDK. My current plan is try to exchange JDK, SDK, and NDK setting between Unity 2017/2019 and do some more tests. I will update this post after get result.)
Update: Unity 2017 + Unity 2019 SDK -> OK Unity 2019 + Unity 2017 SDK -> NG
If nothing else works try Interfaces https://docs.unity3d.com/2019.1/Documentation/ScriptReference/EventSystems.IPointerDownHandler.html