All you need is a boolean to keep track of the current camera state (you currently use “cameraPos”) and 2 different vector3 position offsets (1 for each camera state) and then just switch which one you add on depending on the value of the boolean:
public GameObject player;
private bool cameraPos = true;
private Vector3 offset1;
private Vector3 offset2;
void Start()
{
offset1 = transform.position - player.transform.position;
offset2 = offset1 + new Vector3(0,0,8);
}
void LateUpdate()
{
if (cameraPos)
transform.position = player.transform.position + offset1;
else
transform.position = player.transform.position + offset2;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.E)){
cameraPos = !cameraPos; // make cameraPos the opposite of what it was
}
}