Answer the question
In order to leave comments, you need to log in
How to move the camera with the mouse finger+zoom?
Recently I did all this and it worked perfectly, until I connected the mesh, the fact is that I had a 50x50 2D box Collider object and I rotated it as I wanted, all the objects were actually on it, zoomed in / out, moved with mouse and finger...
private void ZoomEditPanelMap(){
#if UNITY_EDITOR
if(Input.GetAxis("Mouse ScrollWheel") != 0){
PossibleMove = false;
float PrevMapScale = MapScale;
if(Input.GetAxis("Mouse ScrollWheel") > 0) MapScale = MapScale + 0.05f; else MapScale = MapScale - 0.05f;
if(MapScale > MapScaleMax) MapScale = MapScaleMax;
if(MapScale < MapScaleMin) MapScale = MapScaleMin;
if(PrevMapScale != MapScale){
Vector3 Pos = ObjectControlBoard.transform.localPosition;
ObjectControlBoard.transform.localPosition = new Vector3((Pos.x / PrevMapScale) * MapScale, (Pos.y / PrevMapScale) * MapScale, 1f);
ObjectControlBoard.transform.localScale = new Vector3(MapScale, MapScale, 1f);
}
}else PossibleMove = true;
#else
if(Input.touchCount == 2){
PossibleMove = false;
Touch touchZero = Input.GetTouch(0);
Touch touchOne = Input.GetTouch(1);
Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
float deltaMagnitudeDiff = (prevTouchDeltaMag - touchDeltaMag) / 500;
float PrevMapZoom = MapZoomTouch.x;
if(MapZoomTouch.x <= MapScaleMin & deltaMagnitudeDiff > 0) deltaMagnitudeDiff = 0;
if(MapZoomTouch.x >= MapScaleMax & deltaMagnitudeDiff < 0) deltaMagnitudeDiff = 0;
MapZoomTouch = new Vector3(MapZoomTouch.x -= deltaMagnitudeDiff, MapZoomTouch.y -= deltaMagnitudeDiff, 1);
if(MapZoomTouch.x > MapScaleMax) MapZoomTouch.x = MapScaleMax;
if(MapZoomTouch.x < MapScaleMin) MapZoomTouch.x = MapScaleMin;
if(MapZoomTouch.y > MapScaleMax) MapZoomTouch.y = MapScaleMax;
if(MapZoomTouch.y < MapScaleMin) MapZoomTouch.y = MapScaleMin;
MapZoomTouch.x = MapZoomTouch.y;
MapScale = MapZoomTouch.x;
if(PrevMapZoom != MapZoomTouch.x){
Vector3 Pos = ObjectControlBoard.transform.localPosition;
ObjectControlBoard.transform.localPosition = new Vector3((Pos.x / PrevMapZoom) * MapZoomTouch.x, (Pos.y / PrevMapZoom) * MapZoomTouch.x, 1f);
ObjectControlBoard.transform.localScale = MapZoomTouch;
}
}else PossibleMove = true;
#endif
}
public void OnDrag(PointerEventData eventData){
if(PossibleMove){ ObjectControlBoard.transform.Translate(eventData.delta / (Screen.height / 10)); }
}
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