Hey! A have a strange issue - OnPointerDown and OnPointerUp events doesn’t work without any errors in the Editor. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class Touch : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
public bool is_Touched = false;
public void OnPointerDown(PointerEventData eventData)
{
is_Touched = true;
Debug.Log("Dowm");
}
public void OnPointerUp(PointerEventData eventData)
{
is_Touched = false;
Debug.Log("Up");
}
}
and here is my game object with this script:
When I use OnMouseDown and OnMouseUp it works! But I don’t have to use this methods, because they don’t work correctly on my android device. What’s wrong with my OnPointerDown and OnPointerUp script?
Create a canvas, under this one create an image that takes up the whole screen (click on rect image on the left-top corner, use option for mac or ctrl for windows).
So know you have Canvas, with an image full screen. Put your script with OnPointerDown handler or anything else.
Click on your screen
Definately! Otherwise it will call OnPointerUp when you move the knob
I noticed one strange bug with this Pointer interfaces. if your class dosnt implement IPointerMoveHandler, then IPointerUpHandler is called when you first time move pressed finger.
Add IPointerMoveHandler interface with dummy method and check again if it fixed your problem on Android.
I didn't find IPointerMoveHandler interface and added IMoveHandler interface, but it still doesn't work: public class Touch : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IMoveHandler { public bool is_Touched = false; public void OnPointerDown(PointerEventData eventData) { is_Touched = true; } public void OnPointerUp(PointerEventData eventData) { is_Touched = false; } public void OnMove(AxisEventData eventData) { Debug.Log("Move"); } }
Does the object which has this script attached to it have the “Event Trigger” component?
No, it had hasn't. I attached "Event Trigger" component, added new events PoinerDown and PointerUp, drag my gameobject, chose Touch function (script is "Touch.cs"), but there aren't my OnPointerDown and OnPointerUp methods: ![alt text][1] [1]: /storage/temp/143704-1.png
It did help. Thank you.
– Lexudauworked for me. thx.
– Nadir_AlishlyYou're my hero, sir!
– LeonmFFYou also need a 2D collider on the thing you attach pointer down handler to. It didn't work for me when I used a 3D mesh collider, for instance.
– bobbaluba