Need help placing gameobjects just ouside the camera rect.

hii ,
I am making a 2D game for mobiles. I want my character to teleport back into the play area if he goes out side the camera bounds. I achieved this with colliders. But this doesn’t work properly as the phones have different aspect ratios. I want help figuring out 2 things :

  1. How do check if an object goes outside the camera rect
  2. How to do you place gameobjects so that it will be placed along the camera rect edges.

Please help guys…

  1. you can try: OnBecameInvisible
    Unity - Scripting API: MonoBehaviour.OnBecameInvisible()

  2. Camera.ScreenToWorldPoint
    Unity - Scripting API: Camera.ScreenToWorldPoint

1 Like

You may also want to try ViewportToWorldPoint, which is easier to get the camera edges with normalized values than using pixels.

In viewport space, (0,0) is the bottom left corner, and (1,1) is the top right corner.

1 Like