C# transform position

transform.position.x =Mathf.Clamp(transform.position.x, minPosX, maxPosX);
transform.position.z =Mathf.Clamp(transform.position.z, minPosZ, maxPosZ);
Hi, I have these lines in my code and here’s an error:

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

This script is for panning on Android. Someone said that it’s impossible to modify single parameter in C# and you need to convert it into some temporary variable, but I don’t know what to do with “Mathf.Clamp” and the whole line. Help please

This is what they are suggesting by using a temporary variable:

Vector3 pos = transform.position;
pos.x =Mathf.Clamp(pos.x, minPosX, maxPosX);
pos.z =Mathf.Clamp(pos.z, minPosZ, maxPosZ);
transform.position = pos;