Hello Unity Forum,
I work at the moment on a little game to teach me the rules of scripting with C#.
I want to inplement a mouseDragPositionScript where i can move the CameraRig by dragging with the middlemouse.
But my script isnt´t working that well. It updates the new public drag-and currentposition in the inspector when i drag but my camera does not move.
It would be very nice if someone could help me...
Thank you a lot
public Vector3 newPosition;
public Vector3 dragStartPosition;
public Vector3 dragCurrentPosition;
void Update()
{
dragMousePosition();
}
void dragMousePosition()//startMouseDrag
{
if (Input.GetMouseButtonDown(2))
{
Plane plane = new Plane(Vector3.up, Vector3.zero);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float entry;
if (plane.Raycast(ray, out entry))
{
dragStartPosition = ray.GetPoint(entry);
}
}
if (Input.GetMouseButtonDown(2))
{
Plane plane = new Plane(Vector3.up, Vector3.zero);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float entry;
if (plane.Raycast(ray, out entry))
{
dragCurrentPosition = ray.GetPoint(entry);
newPosition = transform.position + dragStartPosition - dragCurrentPosition;
}//endMouseDrag
}
transform.position = Vector3.Lerp(transform.position, newPosition, Time.deltaTime * movementSpeed);//smoothrotation
}