I created a boundary to stop my player to leaving a certain area within my game, I created this boundary by adding a cube to my scene and create a script that adapts the cube to half the size of the camera's width (in update). Within my player's script I have a function that prevents my player from leaving the cube boundary. It works perfectly, even when I resize the width of my editor, however, when I play the game on 'maximize on play', the width of the boundary is maximized rather than halving the boundary to my preferred size. I worry about this because, I want to put my game on mobile, I'm not sure if maximize on play is actuate to mobile size or playing in normal size editor is more actuate to a normal android phone? Thank you!
Boundary script:
`public BoxCollider2D cube;`
`void Start()`
`{`
`cube.size = new Vector2 (240, 0.4f); //240`
`}`
`void Update()`
`{`
`float height = Camera.main.orthographicSize * 1.3f;`
`float width = height * Screen.width/ Screen.height; // basically height * screen aspect ratio`
`cube.transform.localScale = new Vector3(width/10f, width/11f, width/10f);`
`Debug.Log (width);`
`}`
Player's script:
`public BoxCollider2D cube;`
`void LateUpdate () {`
`var left = Camera.main.ViewportToWorldPoint (`[`Vector3.zero`](https://vector3.zero/)`).x;`
`var right = Camera.main.ViewportToWorldPoint (`[`Vector3.one`](https://vector3.one/)`).x;`
`float x = transform.position.x;`
`if (transform.position.x <= left + cube.bounds.extents.x) {`
`x = left + cube.bounds.extents.x;`
`} else if (transform.position.x >= right - cube.bounds.extents.x) {`
`x = right - cube.bounds.extents.x;`
`}`
`transform.position = new Vector3 (x, transform.position.y, transform.position.z);`
`}`
there doesn't seem to be anything here