Skip to content

Instantly share code, notes, and snippets.

@YamilEzequiel
Last active August 3, 2020 08:10
Show Gist options
  • Save YamilEzequiel/745aebbbd25f8ce20ec62a6454f1f218 to your computer and use it in GitHub Desktop.
Save YamilEzequiel/745aebbbd25f8ce20ec62a6454f1f218 to your computer and use it in GitHub Desktop.
Event Button pressed Unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
public class PressedButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
public UnityEvent OnHold;
bool OnPressed;
public void OnPointerDown( PointerEventData eventData )
{
OnPressed = true;
}
public void OnPointerUp( PointerEventData eventData )
{
OnPressed = false;
}
void Update ()
{
if (OnPressed)
{
OnHold.Invoke();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment