How do I do operations with a Vector3 and a Quaternion?

I’m trying to do a basic camera rotation, but it won’t let me set a Vector3 to the camera’s rotation, saying:

Assets/Scripts/Camera Rotate.cs(11,32): error CS0029: Cannot implicitly convert type UnityEngine.Quaternion to UnityEngine.Vector3

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraRotate : MonoBehaviour
{
    public float speed = 20f;
    void Update ()
    {
        Vector3 rotation = transform.rotation;
        if( Input.GetKey("u") )
        {
            rotation.y += speed * Time.deltaTime;
        }
        transform.rotation = rotation;
    }
}

You seem to have trouble to understand what a Quaternion actually is. There are multiple ways to express rotations or orientations in 3d. One common way are Euler angles. Another, completely different way is using a unit quaternion. The components of a quaternion do not represent angles. They are actually resemble a four dimensional complex number.

You almost never want to mess with individual components of a quaternion. It’s a normalized complex number and should be treated as “one thing”. Unlike euler angles which represent three seperate consecutive rotations around world axes, a quaterion can directly represent any 3d rotation as one “operation”. This has many advantages. For example while euler angles can suffer from gimbal lock, quaterions do not have this problem. They also allow direct interpolations between two rotations.

If you want to rotate your object around the y axis you have several options. The easiest one would be to use Transform.Rotate:

transform.Rotate(0, speed * Time.deltaTime, 0, Space.World);

Another solution is to create a relative rotation using either Quaterion.Euler or Quaterion.AngleAxis and rotate the object by this rotation

transform.rotation = Quaterion.AngleAxis(speed * Time.deltaTime, Vector3.up) * transform.rotation;

Note that those examples will rotate around the world up axis. If you want to rotate around the local up vector you would use Space.Self for Rotate and the apropriate axis for AngleAxis which would be transform.up.

It highly depends on your usecase and what method you prefer.

If you are interested in how a quaterion works i recommend this Numberphile video on quaterions