- Home /
Question by
navadeep2011 · Apr 26, 2013 at 06:54 AM ·
dragmousedrag
How will i drag my object with out object disturb?
Hi all,
In a table i have an pendulum set. In that table and set of the pendulum is separate object. my task is when ever i am dragging my table the set also come with that table.
I wrote code like this:
public class DragObject : MonoBehaviour {
public Camera camera;
Vector3 initial,next;
public Transform Table;
// Use this for initialization
void Start () {
camera = GameObject.Find("Main Camera").camera as Camera;
Table= GameObject.Find("Pendulumset").transform as Transform;
initial = transform.position;
}
// Update is called once per frame
void Update () {
}
void OnMouseDrag() {
transform.position = camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition. y,12));
next = transform.position;
next = next - initial;
initial = transform.position;
Table.transform.position += next;
}
}
But the above code is when i am dragging my table that will going but the pendulum set didn't come properly. And i my observation it is also taking click. when i am click the table right side the table mid point comes to that point. table have box collider also.
can any help me on this code. i want only x axis moving.
Comment