- Home /
Question by
Javi89sv · Jun 23, 2019 at 02:01 PM ·
camera-movementpanning
How move camera without move selection?
Hi guys, I need help with my rts game. I want move my camera with mouse, but I´m not want that my selection object is move at same time. How can make this? my code script move camera is this:
void Update()
{
if (Input.GetMouseButtonDown(0))
{
touchStart = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
if (Input.touchCount == 2)
{
Touch touchZero = Input.GetTouch(0);
Touch touchOne = Input.GetTouch(1);
Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
float prevMagnitude = (touchZeroPrevPos - touchOnePrevPos).magnitude;
float currentMagnitude = (touchZero.position - touchOne.position).magnitude;
float difference = currentMagnitude - prevMagnitude;
Zoom(difference * 0.05f);
}
else if (Input.GetMouseButton(0))
{
Vector3 direction = touchStart - Camera.main.ScreenToWorldPoint(Input.mousePosition);
Camera.main.transform.position += direction;
}
Zoom(Input.GetAxis("Mouse ScrollWheel"));
}
Comment