- Home /
Converting Javascript to C# - Cant modify transform.localPosition
Hi,
i have to rewrite a javascript to c# and im new to c#. Its about the following code line:
transform.localPosition.z += (tmpDelta *tmpSpeed);
If i write for c# exactly like the line above, i get a console error:
error CS1612: Cannot modify the return value of `UnityEngine.Transform.localPosition' because it is not a variable
Why and how do i have to correct it? Thanks for your time. yosh
Comment
Best Answer
Answer by biomechanic · Mar 17, 2010 at 03:04 PM
When using c# localPosition's x,y,z components are read-only, so you have to add full Vector3 to position. In your case it would be
transform.localPosition += new Vector3(0f, 0f, tmpDelta * tmpSpeed);