- Home /
This post has been wikified, any user with enough reputation can edit it.
I want to select two cubes with mouse and then drag both of them
i want to select two cubes and then drag them both with mouse, both selected cubes moves at the same direction with mouse, i have a script which only drag one cube at the time pls help me private Vector3 screenPoint; private Vector3 offset; // Use this for initialization void Start () {
}
// Update is called once per frame
void Update () {
}
void OnMouseDown(){
screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
void OnMouseDrag(){
Vector3 cursorPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 cursorPosition = Camera.main.ScreenToWorldPoint(cursorPoint) + offset;
transform.position = cursorPosition;
}
Comment