Need to rotate camera by checking for input then setting the camera's transform rotation += to the new vector3 but it won't work???

Ok. So I’m trying to get the camera to rotate when the player pressed the left and right arrow keys (y rotation). But the problem is that I can’t do a thing where I do cameratransformrotation += newvectorwithadditionalrotation. Here’s the script I’ve tried:

void Update ()

{

if (Input.GetKeyDown(KeyCode.LeftArrow))

{

GetComponent ().transform.rotation.eulerAngles += new Vector3 (0, -1, 0);

}

if (Input.GetKeyDown(KeyCode.RightArrow))

{

GetComponent ().transform.rotation.eulerAngles += new Vector3 (0, 1, 0);

}

Help me please. BTW I’ve also tried a couple other variants, such as Quaternion += new vector3 and Quaternion += Quaternion.eulerAngles but nothing has worked. I really want to finish the game that I am making as I am almost done. It is a golf game, so plzzzzzz help mehhhh. Thanks in advance.

It is my opinion that you should never use euler angles for rotations unless you have no other option. You’ll always end up with issues and I can promise you that.

Instead why not just use transform.Rotate Transform.Rotate

This will “Add” to a rotation the exact way you are attempting but will account for gimbal locking as it uses a quaternion for the rotation (4 vectors instead of 3). So for example, if you want to rotate y + 1 you would use

``````Transform rotateMe = this.transform;  //grab the transform the script is attached to.

rotateMe.Rotate((0, 1, 0) * Time.deltaTime);  //rotate it by y+1
``````

float rx = transform.eulerAngles.x;

float ry = transform.eulerAngles.y;

float rz = transform.eulerAngles.z;

if (Input.GetKeyDown(KeyCode.LeftArrow))
{

transform.rotation.eulerAngles = new
Vector3 (rx, ry-1, rz);

}

if (Input.GetKeyDown(KeyCode.RightArrow))
{

transform.rotation.eulerAngles =
new Vector3 (rx, ry+1, rz);

}