Skip to content

Instantly share code, notes, and snippets.

@DarthMoulByte
Forked from YamilEzequiel/PressedButton.cs
Created August 3, 2020 08:10
Show Gist options
  • Select an option

  • Save DarthMoulByte/9f39a152c9325559a7bcfd163eb1fbb0 to your computer and use it in GitHub Desktop.

Select an option

Save DarthMoulByte/9f39a152c9325559a7bcfd163eb1fbb0 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