- Home /
Unity 4.6 - Detect Touch On Screen
As per the subject line, I'd like an onClick() listener for any touch on either half or all of the screen.
Something like the following but not restricted to the button:
JumpButton.onClick.AddListener(() => {MyFunction(); });
Thank you.
Answer by Nexus2911 · Sep 16, 2014 at 07:40 PM
So, I simply make my jump button as large as the canvas.
This was almost too easy but there is a slight hack - under the Image component of the jump button, I replaced the default image with my own 1024 x768 transparent image. Without an image, the button does not detect a click.
Indeed, OnClick is only called on an object with a collider. But I'm curious...isn't this what Input.touches is for?
$$anonymous$$y jump button does not have a collider and it still registers onClick.
With the new 4.6 update, onClick works in both Unity's game preview window as mouse event and as a touch event on actual devices - at least with iOS it does...
Your answer
Follow this Question
Related Questions
4.6 UI Text rect does not expand automatically 2 Answers
[4.6] How can I make children images not stretch with the parents? where to place anchors? 1 Answer
[Unity 4.6] Button Tracking UI System? 0 Answers
(c#) Photon networking, get players in room? 1 Answer
(4.6) How to apply UI Effects without them becoming part of a UI Mask? 1 Answer