unity rotate camera code example

Example 1: rotate player unity

//This is how you rotate your player left and rigth with the wrrow keys:

public class Test : MonoBehaviour 
{
	public float RotateSpeed = 30f;
   
    void Update () 
    {
        if (Input.GetKey(KeyCode.LeftArrow))
            transform.Rotate(-Vector3.up * RotateSpeed * Time.deltaTime);
        else if (Input.GetKey(KeyCode.RightArrow))
            transform.Rotate(Vector3.up * RotateSpeed * Time.deltaTime);
    }
}

Example 2: unity rotate object relative to camera

transform.rotation = Quaternion.LookRotation(-Camera.main.transform.forward, Camera.main.transform.up);