C# question assigning transform.position.x gets an error

hi
as i know transform will find and returns the Transform component of a gameobject and position is a Vector3 in a transform and X is a valid component of a Vector3 but when i try to set
transform.position.x
in C# it says that x is not a variable
but

transform.position = new Vector3 (0,231,321);

works well
please tell me why
Regards

you can not modify the return of it, you need to get the whole vector (store transform.position in a new vector3), alter x and assign the vector again to transform.position

Actually, it’s because structs are passed by value and not reference. But yeah, pull it into a temp variable, change it there, and set it back.

ah ok learned something again

hi thank you Matthew
i know that structs are passed by value but i am just very careless and new to unity and forgot that vector3 is a struct.
i don’t love them and as jessie leberty in his book said there is no need to them.

thank you
i hope that i will make some casual games and send them to you and you publish them on blurst maybe
i realy love your site and ideas

altho my main work is about making a small virtual world

good luck