- Home /
Force touch to only work on a new touch - buttons
Hi, I am converting my buttons to touches since 2 GUI buttons doesn't work well when pressed together.
the problem is that when i turn it in to touch, I can't force the touch to cancel right after wards. I want to enforce the code to ONLY work on a new touch. (new touch meaning that the player has to lift their finger off the screen, then touch again --- like a button)
when it is a button, it works fine,
if (GUI.Button (Rect, "", font)) {
leftClick = true;
}
if(leftClick){
//do somehting
leftClick = false;
}
This works fine because it only register a "click", the code would not count the continuous touch as a click.
but in touch , if i leave my finger on the "button" then I can't force the "button" to be unpressed (which I need to do). I tried using a tapCount to enforce the touch to be a tap , but that doesn't work.
foreach (Touch t in Input.touches) {
if (RightRect.Contains (t.position)&&t.tapCount==1) {
rightClick = true;
}
}
For example, in game you only want to allow one thing to pass a gate at a time, with gui buttons, the player can leave their finger on the button, but it will only allow one thing to pass. But in touch, if a player leave their finger on there, then it will allow all the things to pass and won't stop after 1 thing. So is there a way to cancel a touch after the user touches the button?
Thanks in advance!
Brush up on touch. Are you going cross platform or just $$anonymous$$obile/Pad?
@meat5000 thanks for your comment, ill look in to that right now. It will only be a ios and android app. mobile / tablet
Ok, some people fall into the trap of using Clicks in their touch-code. Try to avoid any $$anonymous$$ouse references in your touch handling. If you need to use the mouse you can add in Platform specific directive or use something like Application.isEditor to include your mouse code, for editor usage.
Your answer
Follow this Question
Related Questions
detecting touch on gameObject 1 Answer
Button not responsive 1 Answer
GuiTexture touch button problem 0 Answers
How to access other Scripts and Components 1 Answer
Question about user input event handling in Unity game for iOS 2 Answers