2D Toolkit Forum
2D Toolkit => Support => Topic started by: Martin on September 05, 2013, 01:24:11 pm
-
How coul I rotate an object using tk2dUITouch from a tk2dUIItem?
I would like to achieve something similar as the code below, to rotate the object on 3 axis when dragging over it (either mouse or finger).
public class ModelViewer : MonoBehaviour
{
public Transform rotateMe;
private float speed = 200.0f; //how fast the object should rotate
private Vector3 axis = new Vector3();
void Update ()
{
axis.x = Input.GetAxis ("Mouse X");
axis.y = Input.GetAxis ("Mouse Y");
rotateMe.Rotate( axis * Time.deltaTime * speed);
}
}
Code from: http://answers.unity3d.com/questions/10443/how-to-rotate-an-objects-x-y-z-based-on-mouse-move.html (http://answers.unity3d.com/questions/10443/how-to-rotate-an-objects-x-y-z-based-on-mouse-move.html)
-
You need to hook into the OnDown / OnUp and then only run the Update function when the button is "tapped". That should do the job.