- Home /
Zoom camera to touch colliders
Hi everyone,
I have four colliders in the scene that define the bounds of the game area as shown below (colliders are the pink lines and the camera rect is the white box). How can I zoom the camera out until one of its sides touches either the left or the right colliders? I was considering the option of using collision detection but could there be a better way that does not involve collision?
Thanks.
Answer by 101itsme · Apr 07, 2014 at 07:41 PM
Here is what I did.
I have added the following script to the camera. The script zooms the camera out until one of the bounds is in the camera's field of view then a flag is set off to stop the zooming.
public class ZoomOutCam : MonoBehaviour
{
public GameObject boundObject;
// flag to stop zooming
bool stopZooming = false;
void Update()
{
if (boundObject.renderer.isVisible)
{
stopZooming = true;
}
if (!stopZooming)
{
Camera.main.orthographicSize += 0.1f;
}
}
}
Your answer
Follow this Question
Related Questions
Save picture from camera with zoom 0 Answers
How to add Pinch to Zoom? 0 Answers
Zoom camera based on position between player an object 2 Answers
Camera too zoomed in in built game 1 Answer
Over the Shoulder Camera Not Working 1 Answer