Error

I am getting the following error. I cannot figure out what I’ve done wrong, as I am not familiar with using transform.rotation:

Assets/SpaceMovement.js(55,45): BCE0022: Cannot convert ‘UnityEngine.Vector3’ to ‘UnityEngine.Quaternion’.
and
Assets/SpaceMovement.js(55,45): BCE0022: Cannot convert ‘UnityEngine.Vector3’ to ‘UnityEngine.Quaternion’.

Here is the code in which it is occurring, I am attempting to make a spaceship’s x and z rotation to be 0:

function Equalize(){
    //Equalize x rotation
    var e = true;
    var q : float;
    while (e == true){
        q = Mathf.Round(transform.rotation.x);
        Debug.Log("x is " + q);
        transform.rotation = Vector3(q + 1, transform.rotation.y, transform.rotation.z);
        if (transform.rotation.x == 0){
            e = false;
        }
    }
    //Equalize z rotation
    e = true;
    while (e == true){
        q = Mathf.Round(transform.rotation.z);
        Debug.Log("z is " + q);
        transform.rotation = Vector3(transform.rotation.x, transform.rotation.y, q + 1);
        if (transform.rotation.z == 0){
            e = false;
        }
    }
}

You’re trying to assign a Vector3 value to transform.rotation. Transform.rotation is a Quaternion data type. So you will have to assign a Quaternion value to it. The Quaternion class provides several methods to create a new quaternion. Just choose one, and assign the return value to transform.rotation.

Transform.rotation returns a Quaternion, not a Vector3. Try using localeulerangles instead.

transform.localEulerAngles = new Vector3(q + 1, transform.localEulerAngles.y, transform.localEulerAngles.z);