The error you are receiving also explains how to fix it (although I understand why it is not obvious when you read it). Consider to store it in a temporary variable:
Vector3 pos = transform.position;
pos.y = 0;
transform.position = pos;
This is because the position variable has a getter and a setter, which means it can only be modified as a whole, but not partially. The best place for this code would be FixedUpdate though, not Update (since FixedUpdate is not framerate dependent).
↧