polygon collider 2d problem


I work with a 2d project and i stucked since 2 days (unity 4.7.1). I have a simple canvas (screen space overlay) with an image (preserve aspect, anchors: min: 0,0 max: 1,1!!!) and an ortho camera. I added a “polygon collider 2d” component to image with a few points (about five).

If i resizing Game window of Unity, the image resized fine, thx to anchors, but polygon collider not resizing correctly compared to image. Why? How can I make that image and polygon collider resizing together?

Thank You

Unfortunately it’s not that simple. Since you have your canvas defined in screen space overlay, all UI elements will resize based on screen size. GameObjects and other components are only defined in world space and cannot be dynamically resized based on the screen space. Your image should be done using a Sprite and not a UI Image, then the PolygonCollider2D will actually match the Sprite. Dynamically resizing your Sprite and PolygonCollider2D is a pretty expansive topic and everyone has their own method to accomplish that.

Some do calculations to scale their sprites to match the screen resolution (while maintaining aspect ratio), and others actually dynamically load higher/lower resolution sprites (the PolygonCollider2D would have to be changed to match as well).