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