Hello,
Working on a 2D Unity and I stumbled upon moving the camera around that I want to do by dragging anywhere on the screen and upon moving the cursor, the camera follows its movement.
This is what I tried:
-
Made a MouseState struct
struct MouseState
{
public bool LeftButton;
public Vector2 Position;
} -
Checked each Update() for the following:
MouseState OldMS, NewMS;
public Camera TargetCam;void Update() { OldMS.LeftButton = NewMS.LeftButton; OldMS.Position = NewMS.Position; NewMS.LeftButton = Input.GetMouseButtonDown(0); NewMS.Position = Input.mousePosition; if (OldMS.LeftButton && NewMS.LeftButton) { int DeltaX = (int)(OldMS.Position.x - NewMS.Position.x); int DeltaY = (int)(OldMS.Position.y - NewMS.Position.y); TargetCam.transform.Translate(new Vector3(DeltaX, DeltaY)); } }
Yet I do not achieve the wanted result. Halp…