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

Hi, I’ve been researching this error and how to fix it but I can’t seem to figure out how.
If you could point out what’s wrong I would very much appreciate it.

using UnityEngine;
using System.Collections;

public class CameraTrack : MonoBehaviour {
    public float xOffset;
    public float yOffset;
    public GameObject player;
    public Vector3 playerPos;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
        playerPos = player.transform.position;
        transform.position.x = playerPos.x + xOffset;
        transform.position.y = playerPos.y + yOffset;
	}
}

The error is at lines 17 and 18. Thanks in advanced!

You can’t set things to transform.position.x or transform.position.y. You need to do something like:

Vector3 tempPos = transform.position;
tempPos.x += xOffset;
tempPos.y += yOffset;
transform.position = tempPos;

PS: this isn’t related to the question, but do consider caching the ‘transform’ on start, because I see you’re using it in update every frame. It has a hidden GetComponent call and is a little performance intensive. So make a variable such as: Transform myTransform; and then at start say myTransform = transform;

Then you can refer to the transform as myTransform in update. Just a side note.

SpriteState s= new SpriteState();
s.highlightedSprite = Instantiate(Resources.Load(“image”));
tf.GetComponent().spriteState = s;