- Home /
Screen touch issue with IsPointerOverGameObject
Hi!
I'm making a kind of Flappy Bird game to learn a little bit. For now the game works fine, in Unity works as expected, but in mobile there is something that I can't solve.
I have some UI buttons for different actions and the problem is that when you touch them, the game considers that screen touch as a simply action to make the bird fly. Then the bird flies until the top of the screen and dies.
This is my script and I don't know what I'm doing wrong.
void Update() {
if (isDead == false) {
if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject(-1)) {
rb2d.velocity = Vector2.zero;
rb2d.AddForce(Vector2.up * upForce);
anim.SetTrigger("Fly");
}
}
}
Some help, please?
Thanks!
It's because of -1 pointerId parameter. On PC it corresponds to left mouse button but it can be different in touch. So remove that parameter and call IsPointerOverGameObject()
parameterless
Thank you mchts for your answer. I tried what you said but it did'nt work. :(
Your answer
Follow this Question
Related Questions
Detect if player wants to pause or to jump 3 Answers
How to make multiple UI buttons clickable (or in this case tapable) at once. 0 Answers
Converting UI RectTransform to Screen Pixel and vice-versa 5 Answers
Mobile Joystick doesn't work when Mouse Cursor is locked 0 Answers
Grid Layout Group for different screen resolutions 0 Answers