Vector2.Distance on different resolutions

firstTouchPos = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);

endTouchPos = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);

                        //the height of the background(previously scaled to fit the screen) / 10
minSlidedDistance = (int)(SpriteRend.bounds.size.y / 10);

if (Vector2.Distance(firstTouchPos, endTouchPos) > minSlidedDistance)
{
  //do smth
}

This way I check if the player has slided into any direction with a slided distance longer than minSlidedDistance. It works perfectly for different size devices.

Is unity going to make the calculations itself if I simply write minSlidedDistance = 100? I.e. is it still going to work same way on all devices?

P.S. this is not the full code, there are many other IF checks, like the ones for assigning the value to firstTouchPos & endTouchPos

Unity makes the calculations.. i also get confused by this thought with time and again.. You can check it simply by changing the size of Game window, hence its res.

–

Thanks @Priyanshu! I totally forgot about the resolution window in game view. I just checked it and it prints same distances no matter the what screen size is. Post an answer so that I can accept it :)

–

1 Answer

1

Unity makes the calculations. I also get confused by this thought with time and again…

You can check it simply by changing the size of Game window, hence its resolution.