c# multiple camera help
Hi There,
I have setup a simulation, of which it is just running continuously. I have setup some different points of view with cameras all capturing the same thing from different spots. I have used the viewport rectangles of each camera to form a perimeter around the bottom and right side of my screen. The left side and top side of the screen, I would like to have it also be a camera which serves as the "main", enlarged view. When the user clicks on one of the smaller camera view points, it switches the "main" big camera over to this view point.
I have setup UI buttons over each camera to allow the click functionality, but am having trouble scripting the code to make this happen. All of the camera switching code examples I've seen, work by enabling or disabling cameras, but if I do this, it would also disable my small viewport cameras (deal-breaker). Any ideas?
Answer by sys12 · Sep 17, 2015 at 08:05 AM
I think you can do something like updating the rectangles of the cameras. E.g.
Cameras[0].rect = new Rect(0f, 0f, 0.5f, 1f);
http://docs.unity3d.com/ScriptReference/Camera-rect.html
This probably is what you want.
Hey sys12,
I initially did not want to do it like this, but in the absence of any other ideas....I figured it out after a few hours of trial and error. Thanks for the headstart in the right direction.
I stored all my viewport camera rects into rect variables.
private Rect m = new Rect(0.00f,0.33f,0.80f,0.67f);
Setup logic on the button gui scripts to if button A was pressed, set camera A to the main view (and set all other cameras to their stored camera positions).
GameObject.FindGameObjectWithTag("CameraViewaboveSun").GetComponent<Camera>().rect = m;
I then repeated this code for each button, B, C, D, etc.
Only drawback is I now have blank/void spot when a camera from the perimeter moves to the main spot. $$anonymous$$eh.