Instantly share code, notes, and snippets.

Embed
What would you like to do?
Permite agregarle a un botón la posibilidad de llamar una función mientras se mantenga presionado.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
public class UI_HoldButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
public UnityEvent OnHold;
bool IsHolding;
public void OnPointerDown( PointerEventData eventData )
{
IsHolding = true;
}
public void OnPointerUp( PointerEventData eventData )
{
IsHolding = false;
}
void Update ()
{
if (IsHolding)
{
OnHold.Invoke();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment