- Home /
restrict drag within screen
got this script from this site var screenPoint; var offset;
function Update () { } function OnMouseDown() { scanPos= gameObject.transform.position; screenPoint = Camera.main.WorldToScreenPoint(scanPos); offset = scanPos - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z)); }
function OnMouseDrag() { curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z); curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset; transform.position = curPosition; }
how to restrict the object within the screen?
Your answer
Follow this Question
Related Questions
when mouse click a gameobject ,how can I get the position of mouse click gameobject 2 Answers
How can I drag just one object, but not all the objects ? (Android) 1 Answer
My dragging script "Sucks" all the other objects when touching it 1 Answer
How to drag and drop any object to any empty space? 0 Answers
Draggable in Scroll View Returning to proper place on Drop 0 Answers