Hi,
The Target:
suppose there is a plane object and we want drag and drop it with mouse cursor, i found the following code but it gave me error:
Code:
private var currTarget: Transform;
private var dragging: boolean;
private var clickOffset: Vector3;
function Update () {
var objPlane: Plane;
var hitDist: float;
var hit: RaycastHit;
if (Input.GetMouseButton(0) gameObject.name =="Plane") {
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (dragging) {
objPlane = new Plane(Camera.main.transform.forward, currTarget.position);
objPlane.Raycast(ray, hitDist);
currTarget.position = ray.GetPoint(hitDist) + clickOffset;
} else if (Physics.Raycast(ray, hit) Input.GetMouseButtonDown(0) hit.transform.name == "Plane"){
dragging = true;
currTarget = hit.transform;
objPlane = new Plane(Camera.main.transform.forward, currTarget.position);
objPlane.Raycast(ray, hitDist);
clickOffset = currTarget.position - ray.GetPoint(hitDist);
}
} else {
dragging = false;
}
}
Console Output:
NullReferenceException
UnityEngine.Camera.ScreenPointToRay (Vector3 position)
dragObject02.Update () (at Assets/Scripts/dragObject02.js:13)
what is the wrong in the code???