Answer the question
In order to leave comments, you need to log in
How to set the boundaries of the camera movement?
So far, I have set the min-max coordinates of the camera movement restrictions by eye, the movement itself happens like this
private void MoveCamera(){
if(Input.GetMouseButtonDown(0)){ CurrentPositionCamera = MainCamera.ScreenToWorldPoint(Input.mousePosition); }
if(Input.GetMouseButton(0)){
Vector3 DifferencePositionCamera = CurrentPositionCamera - MainCamera.ScreenToWorldPoint(Input.mousePosition);
if(DifferencePositionCamera != PrevPositionCamera){
MainCamera.transform.position += DifferencePositionCamera;
if(MainCamera.transform.position.x >= CameraPositionXMax){
MainCamera.transform.position = new Vector3(CameraPositionXMax, MainCamera.transform.position.y, 0f);
}
if(MainCamera.transform.position.x <= CameraPositionXMin){
MainCamera.transform.position = new Vector3(CameraPositionXMin, MainCamera.transform.position.y, 0f);
}
if(MainCamera.transform.position.y >= CameraPositionYMax){
MainCamera.transform.position = new Vector3(MainCamera.transform.position.x, CameraPositionYMax, 0f);
}
if(MainCamera.transform.position.y <= CameraPositionYMin){
MainCamera.transform.position = new Vector3(MainCamera.transform.position.x, CameraPositionYMin, 0f);
}
PrevPositionCamera = DifferencePositionCamera;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question