- Home /
Taps are not detected on mobile
This is strange. When I test my game in Unity remote this code works just fine (although the buttons, which have an Event Trigger component attached, don't), but when I build it, it seems like no taps are detected (and the buttons work fine!). So, does anybody know why my taps are not detected on my phone (only on the built version)?
public class RotateChY : MonoBehaviour{
bool menuEnabled = true;
bool tapping = false;
[SerializeField] float rotationSpeed = 1f;
[SerializeField] GameObject chHolder;
[SerializeField] GameObject chSelectionScreen;
private void Start() {
chHolder.SetActive(true);
chSelectionScreen.SetActive(false);
}
private void Update() {
if(Input.touchCount > 0) {
Touch screenTouch = Input.GetTouch(0);
if(screenTouch.phase == TouchPhase.Moved) {
menuEnabled = false;
transform.Rotate(0, -screenTouch.deltaPosition.x * Time.deltaTime * rotationSpeed, 0);
}
else if(screenTouch.phase == TouchPhase.Ended) {
if(menuEnabled) {
openChSelectScreen(true);
} else {
menuEnabled = true;
}
}
}
}
public void openChSelectScreen(bool val) {
chHolder.SetActive(!val);
chSelectionScreen.SetActive(val);
}
}
Answer by Mehmedcan · Aug 11, 2021 at 08:59 AM
@MrWy07 Input.touchCount() function not working for mobile. When Unity Remote application is used, the part that appears on the phone is actually compiled by the computer.
You can use:
Input.GetMouseButtonDown(0) // Returns true when user pressed the screen
Input.GetMouseButtonUp(0) // Returns true when user releases the screen
Input.GetMouseButton(0) // Returns true when user held down the screen
InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings.
I think tour answer is great but it seems like I need the equivalent ones for the new input system.
Actually I found it easier to just change the input system to both and now it work perfectly with your functions, thank you ! <3