Camera Rotate script Help.

Hello,

I am doing a side scroller game for my coursework and I have to rotate the camera on the Y axis by 180 degrees.

Currently I have my character moving right with the camera and when I move left I am rotating the character. Because my camera is a child object of my character it rotates as well.

I would like it to stay at the original position just like when I am moving right.

Here is the code I am using to move left/right and rotation of my character.

moveDirection.x += Input.GetAxis("Horizontal") ; 
			
			if(moveDirection.x>speed)
			{
				moveDirection.x = speed;
				transform.eulerAngles = Vector3(0, 90, 0);
			}
			
			if(moveDirection.x<-speed)
			{
				moveDirection.x = -speed;
				transform.eulerAngles = Vector3(0, -90, 0);
				transform.gameObject.camera = Vector3(0, 90, 0); 
				//This should be the code to rotate the camera to the original position.
			}

When I run the following code it shows me the following error

Assets/Scripts/PlatformWalker.js(52,43): BCE0053: Property 'UnityEngine.GameObject.camera' is read only.

I understand I am doing something wrong but because I am just starting in programming I do not know how to fix this error.
If someone could help me it I would much appreciate it.

Regards,
Lukasz K.

transform.gameObject.camera

that’s a reference to the camera object… what about the camera object are you trying to change? camera.eulerAngles?

I want to change the Y angle of the camera by 180 degrees.

What I have now is just like the following pictures

When I move to the Right

When I move to the Left

And This is what I want then I move to the left

Basically camera being transform/rotate into the original starting position