public void Move(){
if(Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began){
Invoke("changeBool", 2f);
}
if(Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Ended){
if(!wasLongTouch){
// Just Rotate the player
CancelInvoke("changeBool");
}else{
// Long Press Detected, move player to touch position
}
}
void changeBool(){
wasLongTouch = true;
}
}
**Tip : ** disable touch when player is moving or rotating … and when there was a long touch do not forget to change wasLongTouch bool back to false when player finished moving
Don’t copy paste this in your code as this is not tested
void Update()
{
Move();
}
public void Move()
{
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Stationary)
{
float startTime = Time.time;
if (startTime >= holdTime)
{
Vector2 touchPosition = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
transform.position = Vector2.Lerp(transform.position, touchPosition, Time.deltaTime);
}
}
}
}
i have this code, when enter in playmode character move to touch point after two seconts hold, but then i need to reset timer called “startTime” after touch is ended. Then do another touch hold to move after 2 second and so on.