Reputation: 109
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
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