Need help with clamp function

ok so I know the problem when I try to clamp it I never reach a clamping range I am looking to clamp it transform on the Z axis the code I have now is this, this is everything I have dealing with this function
I want it to only move 10 degrees either way . Not sure how to add the clamp properly any direction on info would be helpful.

private Transform myTransform;
private Rigidbody rb;
private float rollInput;

void Update
{
          rollInput = Input.GetAxis("Horizontal");

}

void FixedUpdate()
{
        if (Input.GetAxis("Horizontal") != 0)
        {
            Roll(rollInput);
        }
}

void Roll(float rollInput) 
{
        Mathf.Clamp(myTransform.rotation.z, 10, -10);
        rb.AddRelativeTorque(new Vector3(0, 0, 1 * -rollInput));
        Debug.Log(myTransform.rotation.z);
 }

So, a couple of problems here…

  • First, the 2nd two args to Clamp are backwards. Arg #2 should be the min value and arg #3 should be the max value.
  • Second, Clamp returns a value in the range of the min and max values. It doesn’t modify the value you pass in.

So, together, you’d want something like:

float newVal = Mathf.Clamp(myTransform.rotation.z, -10, 10);

Now, you need to use the clamped value (stored in “newVal”) to build a new Vector3, if that’s what you want…