- Home /
Easy way to determine which camera is clicked on?
I have two camera rendering. One fills the view, the other is a smaller rectangle set in one corner of the screen. I can swap these with a script that changes their .rect bounds and swaps their depth. Think of it as a 1st and 3rd person camera picture-in-picture and I can swap them.
Now I want to be able to click on either one, and project a ray to hit things in the scene. Is there a simple clean way of doing this? If I check for Input.mousePosition in bounds of either view, it will always be in the bigger one. I mean I can do this with a bunch of code, but wondering if there was some simple way.
By "a bunch of code" you're really just talking about 4-5 lines
Answer by supernat · Feb 02, 2014 at 07:20 AM
I think it is only 3 lines of code extra.
Camera cam = cameraBig;
if (in rect)
cam = cameraSmall;
Use cam.
It would be much more clear if you did something like:
if (mouse in cam.rect)
in rect
just doesn't say anything at all (and it's actually rect.contains
)
He said he was already checking if the bounds were in a rect, so it was more of a psuedocode statement that I figured he would understand. I didn't have any of his code to start with and didn't have time to go look up all of the correct syntax and variables. I will try to add a "// psuedocode" next time as I can see how that could be unclear.
@blank_reg did this approach work for you?