- Home /
Question by
KAMATLI · Dec 09, 2018 at 05:40 PM ·
mobiletouch controls
Mobile Touch
//Hello guys ,I am trying to develop mobile 2D games but ı have a couple issue ,
//Here are my codes;
if(Input.touchCount >0 )
{
Touch touch = Input.GetTouch(0);
if(touch.phase == TouchPhase.Began)
{
startTime = Time.time;
startPos = touch.position;
}
else if( touch.phase == TouchPhase.Ended )
{
endTime = Time.time;
endPos = touch.position;
}
swipeTime = endTime – startTime;
swipeDistance = (endPos – startPos).magnitude;
if(swipeTime minSwipeDistance )
{
Command(); // Executes anything what ı want (Thats not the point)
}
}
//My problem is touch control executes my command in every frame due to that is created in update().For instance if ı keep pressed screen it executes 16 times until it ends. is there a way to prevent executing multiple times instead of executing once?by the way (touch.phase == TouchPhase.Stationary ) state does not work for me .Please HELP!!!.
Comment