Answer the question
In order to leave comments, you need to log in
How to determine if the ButtonUI button is pressed in Unity or not (via a script)?
Good evening, how to track if the UI button is pressed or not without an Event Trigger? For example: there is a variable of type bool, when the button is pressed, then the variable = true.
Answer the question
In order to leave comments, you need to log in
Class to hang up on the button.
using UnityEngine;
using UnityEngine.EventSystems;
public class BtnHoldDetect : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
public bool isHold = false;
public void OnPointerDown(PointerEventData pointerEventData)
{
isHold = true;
}
public void OnPointerUp(PointerEventData pointerEventData)
{
isHold = false;
}
}
// https://docs.unity3d.com/2018.4/Documentation/ScriptReference/EventSystems.IPointerDownHandler.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question