Artur D
Artur D

Reputation: 109

Cannot modify the return value of 'Transform.position' because its not a variable

for (int i = 0; i < PathLength; i++)
{
    GameObject tile = (GameObject)Instantiate(GroundTile, transform);


    tile.transform.position.x += 1;


}

I am trying to add 1 to the x axis of the tile, so if i add 1 again later it will become 2, however it does not work and I get this error:

Cannot modify the return value of 'Transform.position' because it is not a variable.

Upvotes: 1

Views: 10356

Answers (1)

rustyBucketBay
rustyBucketBay

Reputation: 4551

You need to assign the complete vector3 to the transform.position. Try:

for (int i = 0; i < PathLength; i++)
{
    GameObject tile = (GameObject)Instantiate(GroundTile, transform);


    tile.transform.position = new Vector3(tile.transform.position.x + 1, tile.transform.position.y, tile.transform.position.z);


}

Upvotes: 2

Related Questions