I am trying to keep the sprites I drag and drop to be only in the screen. I don´t want it to be possible to drag and drop outside of the screen view. Is it a good way to solve this so I can change the screen size without any problems later?
This is my code so far :
void OnMouseDown ()
{
screenPoint = Camera.main.WorldToScreenPoint (gameObject.transform.position);
}
void OnMouseDrag ()
{
Vector3 currentScreenPoint = new Vector3 (Input.mousePosition.x, 60, screenPoint.z);
Vector3 currentPos = Camera.main.ScreenToWorldPoint (currentScreenPoint);
transform.position = currentPos;
}
This is to use a drag and drop constraint to the X axis to make my own slider. Now, I need it to stop where the screen ends on both sides of the X axis.