Get a var's value plus X without modifying?

My camera follows (looks at) a GameObject that needs to be at the Player’s 0,0,0. However I want the camera to follow 5 units in front of this GameObject. No matter what I’ve tried, the camera always moved forward 5 units, saves it’s location, so when I run the game, the camera flies away.

void Update(){
    target.position.x += 5f;
}

I basically want to call the line above, WITHOUT saving that value to the actual position.

void Update(){
    Transform temp = target;
    temp.position = new Vector3( temp.position.x + 5f, temp.position.y, temp.position.z );
}

But this does not work either. Any Ideas how I can simply add X to a Transform.Position without moving it, or somehow put that into a temporary Transform that is reset each frame? The point is I need to calculate an offset while keeping the “LookAt” GameObject at player’s 0,0,0.

Thanks!

The top example doesn’t work because you are incrementing and reassigning target.position each frame - that’s what += does.

The bottom example doesn’t work because you’re updating temp, which is a reference to target.

Try this:

Transform temp = target.position + new Vector3(5f, 0, 0);

(Assuming that your object is rotated such that x is forward. Forward is normally z axis)