I am already a few days trying to figure out how can I detect if a few buttons existed long press touch, the new UI interface Unity 4.6 in C #.
Sorry for my bad english, and if I can help or explain would be grateful. I want to have multiple buttons, and each of whether the user has exercised long press touch.
Here is one easy solution for detecting long press.
First of all, I would add an Event Trigger component to each one of my buttons.
On the Event Trigger component of each button, I would add an event type for Pointer Down and an event type for Pointer Up.
I would then code my Pointer Down and Pointer Up to create a ‘long press’.
The function triggered by Pointer Down will be something like this:
public void PointerDown()
{
StartCoroutine(LongPressResult());
}
The function triggered by Pointer Up will be something like this:
public void PointerUp()
{
StopCoroutine(LongPressResult());
}
Finally, you need to code the following which is what will happen on a long press, as well as defining how long is a ‘long press’.
public float LongPressDuration; // you should set this equal to the duration you want for a long press, e.g. 2 seconds.
public IEnumerator LongPressResult()
{
yield return new WaitForSeconds(LongPressDuration);
// Here type the code for what you want to happen at the end of the long press
}