How can you implement the following: there are two UIButton buttons, while simultaneously pressing both, some action must be performed.
1 answer
Try hanging this script on your two buttons.
He has problems
I do not know how it will affect the mobile device, but you can press the button, then press the alt-tab and then
OnPointerUp
will not happen with all the consequences.It will not work to hang this script on another pair of buttons.
using UnityEngine; using UnityEngine.EventSystems; public class GroupAction : MonoBehaviour, IPointerDownHandler, IPointerUpHandler { static int count = 0; bool pressed = false; void Start() { count = 0; } public void OnPointerDown(PointerEventData eventData){ if (pressed) return; pressed = true; count++; if (count < 2) return; Debug.Log("action"); } public void OnPointerUp(PointerEventData eventData){ if (!pressed) return; pressed = false; count--; } }
If you do not like to deal with static and its reinitialization, you can make a link to the associated button, but then there will be a tupny with the mutual indication of the links + the possibility of accidentally breaking this logic by not correctly placing the links in the inspector.
- Thank you very much for your help, it works properly on Android, it is necessary for parental permission before purchasing - GR1995
- one@ GR1995 Well that helped, but be careful with statics - Stranger in the Q
|