So here youβre dealing with the difference between VALUE types and REFERENCE types. Pretty much, the Vector3 and the y float you get are copies so changing them will not affect the transform.
This is why we need to assign the entire Vector3 back to transform.position at once. Otherwise you are changing copies of values and not the actual values the transform is using.