- Home /
Executing Code Once Per Touch
Hi, I'm developing a game for Android in JS, and I need to be able to detect swipes and use these to cycle between locations for a character. My code works, but only with very short swipes, as longer ones cycle more locations than I want. Is there any way to only execute a block of code once per touch or cancel a touch manually to facilitate this?
Example code:
 if (Input.GetTouch(0).phase == TouchPhase.Moved){
     //Execute only once per touch
     var touchMovement : Vector2 = Input.GetTouch(0).deltaPosition.normalized;
     if (touchMovement.x > 0){
         //Move Right
     } else if (touchMovement.x < 0){
         //Move Left
     }
 }
Answer by hav_ngs_ru · Dec 31, 2014 at 07:37 AM
when executed move code - store fingerId of touch in ArrayList, before execute - check if array contains this is and dont execute code for this id. and check TouchPhase.Ended ¦¦TouchPhase.Cancelled, and remove given fingerId on those phases.
or just wait for ended/cancelled without fingerId if you dont need correct mul$$anonymous$$ch
Your answer
 
 
             Follow this Question
Related Questions
Unity touch 1 Answer
Disable gui texture in a different way? 0 Answers
Android touch question 0 Answers
Android touch is not dynamic 1 Answer
android touch input 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                