Detect Button is held or being pressed in unity easy tutorial
ASSALAM o alaikum In this we have shown how to detect if button id being held down or pressed in unity
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ButtonPressed : MonoBehaviour,IPointerDownHandler,IPointerUpHandler
{
bool buttonPressed;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (buttonPressed)
{
print("Button is pressed");
}
}
void IPointerDownHandler.OnPointerDown(PointerEventData eventData)
{
buttonPressed = true;
}
void IPointerUpHandler.OnPointerUp(PointerEventData eventData)
{
buttonPressed = false;
}
}
/*
/////////////////////////////////////////////////////////////////////////////////////////////
ASSALAM o alaikum
All codes and concepts and videos from this channel are non copyrighted and free to use because we believe that knowledge should be freely available for everyone
/////////////////////////////////////////////////////////////////////////////////////////////
*/