Search Unity

Size BoxCollider2D == Camera View size?

Discussion in '2D' started by Syzo, Mar 21, 2017.

  1. Syzo

    Syzo

    Joined:
    Nov 1, 2016
    Posts:
    17
    Hey community
    I have been facing a problem regarding some box colliders positions due to the player's screen resolution, sometimes the user goes off screen and sometimes he doesn't.

    The work around I have been thinking of is attaching a box collider to my camera and resize it depending of the player's screen resolution. My problem is, I don't know how to implement this.

    I appreciate all the answers regarding this matter, feel free to suggest other possible work-around...
     
    strandbergfilip94 likes this.
  2. Ran-Quan

    Ran-Quan

    Joined:
    Mar 16, 2017
    Posts:
    5
    Since you are using 2D, adding colliders as children of a Canvas object is better. It will resize automatically against the screen.

    Here is my setup, works fine

    screenshot.png
     
  3. Syzo

    Syzo

    Joined:
    Nov 1, 2016
    Posts:
    17
    Thank you for your answer, but that won't work for my game :\
     
  4. Ran-Quan

    Ran-Quan

    Joined:
    Mar 16, 2017
    Posts:
    5
    Then what do you need? A full screen box collider? It's also very easy to do it with my approach, just by setting collider's size in OnRectTransformDimensionsChange
    screenshot.png
     
    Syzo likes this.
  5. Syzo

    Syzo

    Joined:
    Nov 1, 2016
    Posts:
    17
    This worked out, thanks dude!
     
  6. SlimBun

    SlimBun

    Joined:
    May 24, 2019
    Posts:
    2
    Sorry for being late, but could you give me the code?