Hello Masters. I have Lets say 10 Sprites on the scene. I move them with drag and drop. But i want each sprites Clamp and not go beyond for specific point.
i move them with this code. (found Here again).
private float startPosX;
private float startPosY;
private bool isBeingHeld = false;
private Vector3 mousePos;
#region Drag And Drop Codes
private void Update()
{
if (isBeingHeld == true)
{
GetMousePos();
gameObject.transform.localPosition = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY, 0);
}
}
private void OnMouseDown()
{
if (Input.GetMouseButtonDown(0))
{
GetMousePos();
startPosX = mousePos.x - transform.localPosition.x;
startPosY = mousePos.y - transform.localPosition.y;
isBeingHeld = true;
}
}
void GetMousePos()
{
mousePos = Input.mousePosition;
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
}
private void OnMouseUp()
{
isBeingHeld = false;
}
#endregion