Skip to content

Instantly share code, notes, and snippets.

@arkms
Created October 11, 2017 23:03
Show Gist options
  • Save arkms/543e331876fa487197a9f565d310cf88 to your computer and use it in GitHub Desktop.
Save arkms/543e331876fa487197a9f565d310cf88 to your computer and use it in GitHub Desktop.
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