Cannot modify a value type return value of `UnityEngine.Transform.position'. Can anyone help ?

Hi. When I save this script

using UnityEngine;
using System.Collections;

public class Camera_Controll : MonoBehaviour {

float margin = 1.5f; // space between screen border and nearest fighter
 
private float z0 = 0; // coord z of the fighters plane
private float zCam; // camera distance to the fighters plane
private float wScene; // scene width
private Transform f1; // fighter1 transform
private Transform f2; // fighter2 transform
private float xL; // left screen X coordinate
private float xR; // right screen X coordinate
 
void  calcScreen ( Transform p1 ,   Transform p2  ){
    // Calculates the xL and xR screen coordinates 
    if (p1.position.x<p2.position.x){
       xL = p1.position.x-margin;
       xR = p2.position.x+margin;
    } else {
       xL = p2.position.x-margin;
       xR = p1.position.x+margin;
    }
}
 
void  Start (){
    // find references to the fighters
    f1 = GameObject.Find("Player1").transform;    
    f2 = GameObject.Find("Com").transform;
    // initializes scene size and camera distance
    calcScreen(f1,f2);
    wScene = xR-xL;
    zCam = transform.position.z-z0;
}
 
void  Update (){
 
    calcScreen(f1,f2);
    float width = xR-xL;
    if (width>wScene){ // if fighters too far adjust camera distance
       transform.position.z = zCam*width/wScene+z0;
    }
    // centers the camera
    transform.position.x = (xR+xL)/2;
}
}

I have error like this

Cannot modify a value type return value of `UnityEngine.Transform.position’. Consider storing the value in a temporary variable

Can anyone help ?

C# has a (stupid) rule that you can only change certain compound variables all at once. The hint “Consider storing the value in a temporary variable” is exactly the fix.

Would have been nice if you wrote the line number, but this line: transform.position.z = zCam*width/wScene+z0; is it. You have to assign transform.position all at once. An easy way is:

Vector3 TP = transform.position; TP.z= ...;  transform.position = TP;

That seems like a giant pain, but in practice, you often want to copy trans.pos into something short like TP before using it a lot (and it runs a tiny bit faster.)