Thx for reply spiney. I’m basically trying to move an object along an axis in the exact same way you would do in the unity editor when clicking on the red/blue/green arrows and dragging your mouse.
Do you know of any tutorials? Everything I’ve seen uses onMouseDrag, etc.
I just figured it out spiney. Why do I always figure it out right after posting?
I found a post that showed how to create a plane and I didn’t know you could do this. This is exactly what I’ve been wondering about.
First I create a plane.
Plane plane;
And then set the plane when user clicks on a gameobject they want to drag.
if (Input.GetMouseButtonDown(0)) {
isDragging = true;
plane = new Plane(transform.up, target.position);
}
And then when I drag I shoot a ray from camera onto the plane and see where it intersects and just set the target position to whatever axis of the hit point.
if (isDragging) {
Ray ray = _.worker.view.ScreenPointToRay(Input.mousePosition);
float hit = 0.0f;
if (plane.Raycast(ray, out hit)) {
Vector3 point = ray.GetPoint(hit);
target.position = new Vector3(point.x, target.position.y, target.position.z);
}
target.position = new Vector3(target.position.x, target.position.y, target.position.z);
}
Now that I’ve learned about planes I feel like I can do anything.