- Home /
How to use mouseUp only on buttons
hello, i have a problem. what i want to do is when player click(and hold) anywhere in the world 3 button will pop up beneath of the cursor, and the button which mouse released on works. im tried to use unity event trigger mouse up thing in unity it didnt work in order to make it work both mouse down and mouse up need to be on button. however, in my case mouse down on another place , mouse up only on button. i even tried to code event system but it had same result with unity"s event trigger . what should i do? here my code btw public class ButtonUpMouse : MonoBehaviour, IPointerUpHandler,IPointerDownHandler { bool pointerUp; public UnityEvent onMouseUp;
void Start()
{
pointerUp = false;
}
void Update()
{
if (pointerUp)
{
if (onMouseUp != null)
{
onMouseUp.Invoke();
}
Reset();
}
}
public void OnPointerUp(PointerEventData eventData)
{
pointerUp = true;
Debug.Log(pointerUp);
}
private void Reset()
{
pointerUp = false;
}
public void OnPointerDown(PointerEventData eventData)
{
}
}
Your answer

Follow this Question
Related Questions
OnMouseUp and GUITexture 1 Answer
detect click on collider like button 1 Answer
OnMouseUp interfering with NGUI OnClick Button 1 Answer
Calling method once 2 Answers
Event trigger for instantiated objects 0 Answers