Reputation: 351
Can anybody share their experience on how to fit the Gameobject within the camera's view port/FOV by moving the camera without scaling the gameobject neither the camera. Here the point is I don want to change the scale of the object, I only want to move the camera.
Edit: I have added a box collider to the GO, Now How to fit the Collider to camera?
Regards, Jithendrakumar.
Upvotes: 0
Views: 528
Reputation: 351
Below is the answer, i have found and working for all GO's regardless whatever the scaling is. Here i have used cube as a test object with BoxCollider.
Camera.main.transform.position = Cube.transform.position + Cube.transform.forward * -(2 * Cube.GetComponent<BoxCollider>().bounds.size.y);
Upvotes: 1