The camera in my scene is stationary, and I want to be able to pick up objects that spawn and move them by dragging them with the mouse. It is working for the most part, except that the objects randomly drop while the mouse button is still being held.
{
public Camera gameCamera;
void Update()
{
Ray ray = gameCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo) && Input.GetMouseButton(0) && hitInfo.collider.gameObject.CompareTag("MoveableObject"))
{
hitInfo.collider.gameObject.transform.position = gameCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 8));
}
}
}
Here is what it looks like when playing: