Detect Button is held or being pressed in unity easy tutorial

Subscribers:
1,110
Published on ● Video Link: https://www.youtube.com/watch?v=03mCu-l8u28



Category:
Tutorial
Duration: 2:24
756 views
16


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
/////////////////////////////////////////////////////////////////////////////////////////////
*/




Other Videos By Muhammad Shahzaib


2022-10-02Solved Texture stretching issue in unity easy tutorial
2022-09-29Sensor based door open/close unity tutorial | Slide door using sensor in unity3d
2022-09-27Show private variable in inspector and hide public in inspector unity3d
2022-09-25Play Pause Audio in unity3d
2022-09-22Solved Lens flare not visible in camera or game issue in unity| Flare layer in unity
2022-09-21Highlight selected button in unity easy tutorial
2022-09-18Change default cursor detailed video tutorial in unity|#unity
2022-09-15Solved You uploaded a debuggable APK or Android App Bundle unity
2022-09-14Camera follow jerk issue solution in unity3d
2022-09-13Find and change shortcut keys in unity tutorial | Shotcut keys in unity
2022-09-12Detect Button is held or being pressed in unity easy tutorial
2022-09-11Make world UI always always look at camera unity tutorial | Rotate gameObject towards camera unity
2022-09-04Effect all ui elements in group using Canvas Group unity| Canvas Group in unity
2022-09-04Attach trailer with truck using joints in unity3d
2022-08-31Balance rigidbody in unity3d | Balance rigidbody character from fall on hitting unity
2022-08-31When your game character is too much down to earth
2022-08-29Develop sun in unity3d | Add custom sun in unity3d | Lens flare in unity3d
2022-08-28Enable hinge joint and car door physics on collision unity3d | Simple car hit effect in unity3d
2022-08-27GTA like car doors effect in unity3d | Unity door physics | Hinge joint in unity
2022-08-24Wind Zone in unity | Bend trees using wind zone in unity | How to add trees on terrain
2022-08-23Simple waypoint follow AI in unity | Patrolling AI in unity3d | Waypoint system unity



Tags:
unity
unity2d
unity3d
learn unity
unity tutorials
button held in unity
button being pressed in unity
detect button held in unity
unity ui
unity ui button tricks