Laman

Unity OnMouseDrag

Move Object with dragging mouse / drag object with mouse
Script:
float distance_to_screen;
Vector3 pos_move;
void OnMouseDrag(){
 distance_to_screen = Camera.main.WorldToScreenPoint(gameObject.transform.position).z;
 pos_move = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance_to_screen ));
 transform.position = new Vector3( pos_move.x, pos_move.y, pos_move.z );
}

No comments:

Post a Comment

Silahkan