Rotate an element with exactly value

Hello!
I have to rotate the Z axis of an element with [-140, 140] range.
How can I do this?
I tried use transform.rotation.z = but without sucessfully.
Thanks!

You are trying to modify a 4D Quaternion (transform.rotation). It is recommended not to modify quaternions directly unless you understand Quaternions. An alternative is transform.eulerAngles. But you have to be careful with these as well. Quoting from the scripting reference:

Do not set one of the eulerAngles axis separately (eg. eulerAngles.x = 10; ) since this will lead to drift and undesired rotations. When setting them to a new value set them all at once.

Typically the way I write code to deal with eulerAngles and localEulerAngles is to maintain my own Vector3 and assign to (but never read from) eulerAngles. For most rotations, there are more than one euler angle representation, so you cannot depend on the values. Here is a bit of untested example code.

var v3Rotate = Vector3.zero;
var min = -140;
var max =  140;
var rotateSpeed : float = 45.0;
 
function Start() {
    transform.localEulerAngles = v3Rotate;
}
 
function Update () {
    v3Rotate.z += Input.GetAxis("Mouse X") * rotateSpeed * Time.deltaTime;
    v3Rotate.z = Mathf.Clamp(v3Rotate.z, min, max);
    transform.eulerAngles = v3Rotate;
}