How to find a camera in purticular camera’s view position ? For example
In this example , mouse position in " Camera 2 " view . How to find mouse position in camera view( Not using Raycast or OnMouseOver() function )
How to find a camera in purticular camera’s view position ? For example
In this example , mouse position in " Camera 2 " view . How to find mouse position in camera view( Not using Raycast or OnMouseOver() function )
Use Camera.ScreenToViewportPoint to get the mouse’s position relative to the camera’s viewport.
If both X and Y are between 0 and 1, then it is within the camera’s viewport, otherwise it is outside:
public Camera GetCameraForMousePosition() {
Camera[] allCameras = Object.FindObjectsOfType(typeof(Camera)) as Camera[];
foreach (Camera camera in allCameras) {
Vector3 point = camera.ScreenToViewportPoint(Input.mousePosition);
if (point.x >= 0 && point.x <= 1 && point.y >= 0 && point.y <= 1) {
return camera;
}
}
return null;
}