- Home /
 
               Question by 
               peterraikap · Jun 14, 2020 at 11:59 AM · 
                unity 5touchtouch controlslocalscale  
              
 
              How to limit pinch scale of an object in AR?
Hello, im new to Unity and i would like to know whats the best way to limit localScale of an Object thats been scaled via touch gesture in AR? The user shouldn't be able to scale up the object to high/low.
My code:
     void Scale()
     {
         Touch t1 = touches[0];
         Touch t2 = touches[1];
 
         if (t1.phase == TouchPhase.Began || t2.phase == TouchPhase.Began)
         {
             initialFingersDistance = Vector2.Distance(t1.position, t2.position);
             initialScale = curSelected.transform.localScale; 
         }
         else if (t1.phase == TouchPhase.Moved || t2.phase == TouchPhase.Moved)
         {
             float currentFingersDistance = Vector2.Distance(t1.position, t2.position);
             float scaleFactor = currentFingersDistance / initialFingersDistance;
 
             curSelected.transform.localScale = initialScale * scaleFactor;
         }
     }
I appreciate any help :)
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                