Change position directly

I have it like this, when i press a button. In this case A or D, my cube (Children of my parent) has to move to the opposite side of my Player (Holding the cube). So the cube is the way, the character is facing / moving. 2D Platformer.

This is my code, that should work, but it doesn’t.

transform.GetChild(0).transform.position.x = transform.position.x - 1.5f;

Im getting the error:

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

You’ve got to add a temp var like this

Vector3 pos = transform.GetChild(0).position;
		pos.x = pos.x - 1.5f;
		transform.GetChild(0).position = pos;

Because you can’t change directly x, y z values of a transform position.
but you can assign a new position.