- Home /
Is it possible to view two camera at the same time?
I have a problem. I am trying to have two cameras active at the same time and have them move in (slide in to view)
For instance i have two layouts and the camera on both is not showing them. Then i have a lerp function that slides the camera onto one layout and away from another (eg slideIn/SlideOut like on Android). The sliding works fine, my major problem is showing both slide in and slide out. What happens is that when i activate a camera it shows white background and a slide in but the other camera that is sliding out dissapears.
Is it possible to render both cameras at the same time?
Answer by Seth-Bergman · Jul 27, 2012 at 03:28 PM
Just use the "Normalized Viewport Rectangle" settings to set the part of the screen that the camera should be visible.
from a script you can access it as a Rect using Camera.rect
Camera.main.rect = new Rect(x,y,w,h);
so I figure using a simple lerp on the x value should achieve what you want
So what your saying is that i would have a camera on each layout rectangle then set viewport as first layout, click a button then lerp though the rectangle until it shows the whole second layout?
yes.. you could say for example:
camera1.rect = new Rect(camXvalue,0,Screen.width,Screen.height);
camera2.rect = new Rect(camXvalue+1,0,Screen.width,Screen.height);
then just lerp camXvalue from -1 to 0
untested, but you get the idea
Thanks that is exctly what i needed.
Edit: I have been trying this for the last 2 hours but i cannot seem to get this. when i lerp the x value it the camera is snapped to the new one at the end of my tween function. Is it possible to set camera outisde of screen (eg: screenWidth = 480) then set x at -480? Edit again::
$$anonymous$$y problem was that ins$$anonymous$$d of the camX values of -1 to 0 i was using 480 to 0 , that is why it was jumping. After i switched to (0,1) range everytying was good.
Also Seth, When i change the camera sizes from -1 to 0 or even 0-1 , I see the rectangle getting smaller (ins$$anonymous$$d of moving out of the screen) and my camera stays in the center (not moving the whole thing away like i would think it does. Do you know why something like that might happen.
not quite sure what you mean.. the Rect struct goes:
(leftmostPoint,topmostPoint,width,height)
if you adjust the width or height, that should affect the size
the first two coordinates mark the position of the top-left corner, but do not affect size
changing the "size" parameter (of an orthographic camera), will not change any of this, it will simply change what the camera can see, (it's like a zoom), but the screen coordinates for the Rect will not be affected, just the "zoom" of what's inside it
Answer by DaveA · Aug 01, 2012 at 12:52 AM
There is a set of scripts on the Script Wiki that does this and more. When that comes back online, you should grab it. Can do a bunch of different 'wipes'