Just curious, but how do you distinguish between a tap and a hold on the iPhone. Just looking at the different keywords we have, I thought it might have something to do with TouchPhase.Began and TouchPhase.Stationary, but nothing I’ve tried works.
I’m trying to set up a timer through the update function that says GetMouseButton, timer += Time.deltaTime and then once the timer exceeds a certain value (0.7s) then it will be considered a hold but I can’t find a similar function for GetMouseButton via the Touch controls.
Whatever method I use, it will need to coexist with flick and double tap controls as well.
Any suggestions or links to good iphone control resources?
This is the code that I’m juggling at the moment.
void Update()
{
if(Input.touchCount > 0)
{
//start timer
holdCount += Time.deltaTime;
if(holdCount > 0.7f)
{
//input counts as a hold
holdState = true;
//User releases hold (works but reluctant to use as I've heard TouchPhase.Ended gets skipped a lot)
if (Input.GetTouch(0).phase == TouchPhase.Ended)
{
//holdStuff happens & reset
holdState = false;
holdCount = 0;
Debug.Log("Hold finished")
}
}
else
//input counts as tap
if ((Input.GetTouch(0).phase == TouchPhase.Ended) && (holdState == false))
{
Debug.Log("Instantiate object");
holdCount = 0;
}
}
}