Having trouble making my camera orbit an object

I’ve got simple planetary bodies orbiting a sun, that works fine. However, I have a fixed camera for each planet (every planet is a prefab combination of planet and child camera). I’m trying to get the camera to rotate around the planet, always facing it, by use of arrow keys.

if(Input.GetKey(KeyCode.LeftArrow)){
    	transform.RotateAroundLocal(Vector3(0, -CameraRotate, 0), CameraRotate * Time.deltaTime);
    	transform.localPosition(0, 0, 0);
}

The first line works just fine, and rotates the camera to the left. I have an identical code group that does the opposite.

My problem is the second line. I initially assumed that it would reference the camera itself, just like the line above. Unfortunately, I get the following error:

BCE0077: It is not possible to invoke an expression of type 'UnityEngine.Vector3'.

Unless I’m wrong, this means I’m not referencing the camera but instead attempting to tell the entire game to rotate. Is that right? I’ve tried every variation I can think of, from Object.tranform to gameObject.transform; they work, to a point, but I get a null error telling me an object is being referenced that isn’t there (probably misremembering that).

So far I’ve been exploring about camera scripting on the Asset Store. One solution I found was from the Camera Orbit Tool where you parent your camera to an empty game object and rotate that game object instead of the camera. This will give a distance between the camera and the object that the camera is orbiting.

So in your case, you might want to create an empty game object on each planet and parent your camera to that empty game object. You can then attach a script to rotate the parent, causing the camera to orbit each planet.

I hope I get your question right and get your problem solved.

Your problem is on the third code line. I think you want:

if(Input.GetKey(KeyCode.LeftArrow)){
        transform.RotateAroundLocal(Vector3(0, -CameraRotate, 0), CameraRotate * Time.deltaTime);
        transform.localPosition = Vector3(0, 0, 0);

}