Here’s a small snippet of my code that I’m having troubles with. I’m trying to allow the user to move objects around a scene by “grabbing” them with their finger and physically moving them. However, I only want this to happen when they grab an object with a tag of “moveable”. Otherwise, I’d like this gesture to move the camera. Here’s my code:
private var currTarget: Transform;
private var dragging: boolean;
private var clickOffset: Vector3;
var cam: Transform;
function Update () {
var objPlane: Plane;
var hitDist: float;
var hit: RaycastHit;
if (Input.GetMouseButton(0)) {
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (dragging) {
objPlane = new Plane(Camera.main.transform.forward, currTarget.position);
objPlane.Raycast(ray, hitDist);
if (hit.tag == "Wall"){
currTarget.position = ray.GetPoint(hitDist) + clickOffset;
}
else{
cam.position = ray.GetPoint(hitDist) + clickOffset;
}
} else if (Physics.Raycast(ray, hit) Input.GetMouseButtonDown(0)) {
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;
}
}
The problem I’m having is that Unity is telling me:
Can anyone help me? Thank you in advance.