- Home /
how to controll second camera (MiniMap)?
so i got a second camera that is at the bottom of the screen(shows all the map) and serves as a minimap.
now i wanted to add:
1) a little square to show where the first camera is.
2) a sort of click listener, meaning when i click on the minimap i want the main camera to move to that location.
so my question is how can i do it in the right way?
ty in advance :)
Answer by Mr.Hal · May 03, 2014 at 05:46 PM
For the little square, Make a quad that's on a layer the mini map camera renders(You could parent it to the first camera). And that's no code required.
For the click "Listener", A physics raycast of Camera.ScreenPointToRay(Input.mousePosition) should give a Ray that will give you the location of where the mouse struck, Then its a matter of moving the main camera... Do this while the mouse is over the "PixelRect" of the Camera and while the mouse is actually clicking.
if (MiniMapCamera.pixelRect.Contains (Input.mousePosition) && Input.GetMouseButtonDown (0)) {
Ray MouseRay = MiniMapCamera.ScreenPointToRay (Input.mousePosition);
MainCamera.transform.position = MouseRay.origin;
}