- Home /
Why you can't simply transform.position.x = somefloat or transform.rotation.eulerAngles = somevec3?
Instead you need to do BS like that:
//oh for fuck's sake! For a moment I've thought Unity is a normal engine where such shuffling
//isn't needed. But no, you can't simply do transform.rotation.eulerAngles = someVec3;, you have do this BS.
Quaternion quat = rt.rotation;
quat.eulerAngles = normalRot;
rt.rotation = quat;
or this:
Vector3 currentpos = this.transform.localPosition;
float newy = defaulty + (Mathf.Sin((Time.timeSinceLevelLoad * Mathf.Abs(shipSpeed))) * Mathf.Abs(sinAmp));
currentpos.y = newy;
currentpos.x += shipSpeed;
this.transform.localPosition.localPosition = currentpos;
Answer by incorrect · Jun 14, 2018 at 06:32 PM
Because transform.position and transform.rotation are properties, not fields. They return the copy of position and rotation, not the references to the actual position and rotation.
I would suggest you to get deeper into C# to understand the difference. And read about how Unity works to understand why it's implemented this way. (long story short, if I understand it correctly, position and rotation are stored in a core C++ part of Unity for performance purposes, so you get access to them from C# via properties)
Your answer
Follow this Question
Related Questions
Designing a interior for horror game... Need help :C 2 Answers
Bad performance on certain android devices 1 Answer
Spawning System 2 Answers
Restoring folders/files deleted from Unity 0 Answers
Efficient Background for Bridge 0 Answers