- Home /
Question by
charlesjustinego · Jul 13, 2014 at 11:24 AM ·
javascripttargetdrag and drop
How to add Drag and Drop Target
My drag and drop is efficiently working. It is just that I wanted to add a target wherein draggable items are expected to be placed. Or else, the draggable object will return to its origin.
Here is my code:
pragma strict
rivate var ray : Ray; private var hit : RaycastHit;
function Start () {
}
function Update () { if(Input.GetMouseButton(0)){ ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast(ray, hit)){ transform.position.x = hit.point.x; transform.position.y = hit.point.y; }
}
}
In this case, draggable object can be drag anywhere. Thanks!
Comment