Jump to content
  • Advertisement
Sign in to follow this  
ZeroRadius

Unity : OnPointerUp is firing at same time as isPointerDown on UI Button

This topic is 820 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys and gals,

 

So I'm working in unity using C#. I am trying to get OnPointerUp / OnPointerDown to work. Right now I'm just using Debug.Log() to show that everything is working correctly. At first I had the Debug comands in the OnPointerUp / OnPointerDown methods and everything worked as expected. Then I moved the debug statements to the Update method and used an if/else statement to determine if the button is up or down. The weird thing is that the message to be shown  OnPointerUp  executes continuously even if I have the mouse pointer down. The message for OnPointerDown only goes when the mouse pointer is down. 

 

I tried switching the else to an if else (I knew it would not work but i'm desperate) and I changed the Debug message to make sure that I don't have a random message in another code displaying the same thing.

 

 

Here's my code:

using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems; //Added

public class MultiTouchForMobile : MonoBehaviour, IPointerDownHandler, IPointerUpHandler {
    public GameObject Target;
    private bool isDown = false;//Is the button currently being held down
    private bool undo = false;//Keeps track of wether decrement has been called. If true decrement has not been called
    private float downTime;

    public void OnPointerDown(PointerEventData eventData) 
    {
        this.isDown = true;
        //this.downTime = Time.realtimeSinceStartup;
    }
    public void OnPointerUp(PointerEventData eventData)
    {
        this.isDown = false;
    }
    void Update()
    {
        if(isDown)
        {
            Debug.Log("Down");
        }
        else
        {
            Debug.Log("UpEvent");
        }
    }
    public void Ignore()
    {
        Target.GetComponent<PlayerMovement>().AddIgnored();
    }
}

Thanks in advanced,

Zero

Share this post


Link to post
Share on other sites
Advertisement

(>.<) Wow, yah it was also attached to a empty Game. I forgot I originally had this script set up for OnClick and thus had it attached to  a empty game object. Seriously I read your reply and went "I wouldn't do that" then decided to double check everything in the hierarchy and found it. Thank you For the help and I'm sorry that I wasted your time.

Share this post


Link to post
Share on other sites

You can use parameters or log the game object directly.  It can save a lot of time and hair pulling to do Debug.Log("OnPointerUp" + this.name);

 

Or Debug.Log("OnPointerUp", this.gameObject), 

Edited by ferrous

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!