- Home /
Rotate an ingame 2D object via script just like the rotate tool
I have a 2D sprite which I want to rotate just like the rotate tool in the editor. The following script I have rotates the object in all axis I just want rotation in z axis just like the rotate tool with mouse .I am totally new to programming and really need some help.
public float RotateSpeed = 15f;
void OnMouseDrag()
{
transform.rotation = Quaternion.AngleAxis( Input.GetAxis("Mouse Y") * RotateSpeed, Camera.main.transform.right) * transform.rotation;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613013536im_/https://answers.unity.com/themes/thub/images/avi.jpg)