spinning an object with mouse movement

Hey folks, I want to be able to swipe my mouse on the screen in a certain direction and have a floating on-screen cube rotate in a that direction, kind of in the same way it would look if the cube was static and the camera were to orbit around the cube - I want the cube to spin in the direction of mouse movement, basically.

for another example of what I’m trying to get at, think of what happens when you go to rotate an object in the editor with the rotation gizmo. click on the gizmo, but not on a specific axis – between the axis, the object rotates in the direction of your mouse. that’s the effect I want, but without the gizmo…

Anyone have any ideas?


I made this for picking up and rotating physics objects for an adventure game, but I’ve stripped it down. Mouse X/Y should be in Project Settings > Input by default.

using UnityEngine;
using System.Collections;

public class ObjectRotate : MonoBehaviour {
	public float multiplier = 10f;
	void OnMouseDrag()
		transform.Rotate(Input.GetAxis("Mouse Y") * multiplier, -Input.GetAxis("Mouse X") * multiplier, 0, Space.World);