Hi! My question would be this: How can I limit the rotation of an object, because it seems like the Mathf.Clamp doesn't work have I wanted it. I want it on the x and on the z axis (Im new to Unity))

using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Runtime;
using UnityEngine;

public class swordrotation : MonoBehaviour
{

public float mouseSensitivity = 100f;

public Transform SwordRotation;

float xRotation = 0f;
float zRotation = 0f;
// Start is called before the first frame update
void Start()
{
    Cursor.lockState = CursorLockMode.Locked;
}

// Update is called once per frame
void Update()
{
    
    if (Input.GetMouseButton(0))
    {
        float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
        float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;

        xRotation = Mathf.Clamp(xRotation, -40, 60);
        zRotation = Mathf.Clamp(zRotation, -90, 90);

        SwordRotation.Rotate(new Vector3(10f, 0f, 0f) * mouseY);
        SwordRotation.Rotate(new Vector3(0f, 0f, 10f) * mouseX);
    }
}

}

To clamp the rotation of an object you should keep track of your rotation angles and set the rotation every frame, something like this -

public float xMin = -40f;
public float xMax = 60f;
public float zMin = -90f;
public float zMax = 90f;

private Vector3 rotation;

void Update(){
    mouseY = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
    mouseX = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;

    float xRotation = Mathf.Clamp(rotation.x + mouseX, xMin, xMax);
    float yRotation = Mathf.Clamp(rotation.y + mouseY, yMin, yMax);
    rotation = new Vector3(xRotation, yRotation, 0);
    
    SwordRotation.rotation = rotation;
}

Where you can clamp your overall rotation values, then apply those clamped values every frame