On mouse drag don’t work anymore when I change the following canvas settings:
screenspace overlay → screenspace camera
UI scale mode: scale with pixel size → scale with screen size and reference resolution to HD 1920x1080
Here is the script I have for the dragging function:
public class ObjectPlacement : MonoBehaviour
{
private Vector3 mOffset;
private float mZCoord;
//Instantiate()
//disable view from player's inventory
#region Dragging furnitures to place
private void OnMouseDown() {
if (FindObjectOfType<HouseUICtrl>())
{
if (FindObjectOfType<HouseUICtrl>().isDecoreting)
{
if (!GetComponent<SitOn>().OnClick)
{
mZCoord = Camera.main.WorldToScreenPoint(gameObject.transform.position).z;
mOffset = gameObject.transform.position - GetMouseWorldPos();
}
}
}
}
private Vector3 GetMouseWorldPos()
{
Vector3 mousePoint = Input.mousePosition;
mousePoint.z = mZCoord;
return Camera.main.ScreenToWorldPoint(mousePoint);
}
private void OnMouseDrag()
{
if (FindObjectOfType<HouseUICtrl>())
{
if (FindObjectOfType<HouseUICtrl>().isDecoreting)
{
if (!GetComponent<SitOn>().OnClick)
{
transform.position = GetMouseWorldPos() + mOffset;
GetComponent<Rigidbody>().isKinematic = true;
}
}
}
}
private void OnMouseUp()
{
GetComponent<Rigidbody>().isKinematic = false;
}
#endregion
}