unity transform rotate around local code example
Example 1: how to change rotate with script unity
var rotationVector = transform.rotation.eulerAngles;
rotationVector.z = 0;
transform.rotation = Quaternion.Euler(rotationVector);
Example 2: unity smoothly rotate
private float desiredRot; public float rotSpeed = 250; public float damping = 10; private void OnEnable() { desiredRot = transform.eulerAngles.z; } private void Update() { if (Input.GetMouseButton(0)) { if (Input.mousePosition.x > Screen.width / 2) desiredRot -= rotSpeed * Time.deltaTime; else desiredRot += rotSpeed * Time.deltaTime; } var desiredRotQ = Quaternion.Euler(transform.eulerAngles.x, transform.eulerAngles.y, desiredRot); transform.rotation = Quaternion.Lerp(transform.rotation, desiredRotQ, Time.deltaTime * damping); }