First of all I want to describe what I have in my scene. 1. Joystick. 2. Main character that has link to joystick and handles touch events from joystick. 2. Buttons. 3. Other GameObjects that must handle touch events.

But that's not all. When player is touching any part of screen (except of the above objects) main character must start fighting. The problem is in that I cant correctly handle all touch events on these game objects. When the player is touching to the joystick the main character starts moving but before this he is performing a single fight action. Can anyone give me some ideas how to correctly handle touch events on different gameobjects? Perhaps my question is confusing, I am sorry for this.


You have to route the input by priority or z-order. First check HUD or GUI elements (on top) and the actual world ground at last (beneath). If a valid touch target is found/hit then you have to consume the input ond not routing it any further.

Think of it as layers, for example

[Touch] -> [Button] -> [Character] -> [Ground]

Every touch will at least hit the ground. When a touch event occurs you start start with all GUI elements like buttons. If no button was hit then you check all characters and then where on the ground the touch hit the level.

If a button was hit you trigger its action and do not check the others (characters and ground). The input is consumed by the first object being hit.

  • \$\begingroup\$ I am sorry, but I didn't understand Your answer. How can I set this z-priority? Or I need to send raycasts on touch events and my gameobjects must have different z-coordinates? \$\endgroup\$ – bukka.wh Dec 12 '14 at 13:59
  • \$\begingroup\$ @bukka.wh I clarified my answer. \$\endgroup\$ – aggsol Dec 12 '14 at 14:10
  • \$\begingroup\$ I am sorry for such a late reply((( Thank you very much. I choosed your solution and it helped me. \$\endgroup\$ – bukka.wh Dec 24 '14 at 13:20

If your touchables overlap, what you are "touching" is ambiguous unless you process the input by the z-order or user-defined precedence of the touchables (Code Clown's solution). You would have to handle this ordering of touch event receivers in a higher level of your code so that the touch event can be stopped by the first receiver in the hierarchy.

The simpler solution is to just not let your touch zones overlap. Instead of reacting immediately to the "touch begin" event on the full screen zone, check to see if the coordinates of the touch overlap any other touchables. If they do, then this isn't an event that your full screen zone should respond to.

  • \$\begingroup\$ Thank you for the answer. I'll try your solution and Code Clown's solution and the I'll write about which solution helped me)) \$\endgroup\$ – bukka.wh Dec 12 '14 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.