- Home /
Line Renderer and Sprite Z-coordinate always 10?
This is the weirdest thing. I set the sprite's Z coordinate in every update. I check it at the start and at the end, but it is always 0 when I print out the transform.position. However, when I look in the inspector, the Z coordinate for this object is always a 10. I never manually set the value to any other than a 0, yet it is a 10.
This causes an issue. I use LineRenderer to render some lines and setting "Sorting Layer" on the Line Renderer appeared to have no effect on where it was rendered and thus, I'm using the Z coordinate. However, it magically turning into 10 is weird. Furthermore, the actual sprite being rendered is a child object of the magic object that goes to 10. (Weirdest part is that before and after the Update that moves the object, the value appears to be correct).
Anyone ran into anything like this before? I could give out some code, but I don't even know what's relevant here. Setting the position is always done with
this.transform.position = new Vector3(x, y, 0);
Yeah, that appears to be the issue, thanks! (If you post that as an answer ins$$anonymous$$d of a comment, I'll accept it as an answer). Didn't realize the parent objects had Z coordinates other than 0.
Answer by maccabbe · Jun 05, 2015 at 10:23 PM
Does the sprite have a parent? The inspector displays the local coordinates while transform.position sets the global coordinates. To set the localPosition use transform.localPosition, i.e.
transform.localPosition=new Vector3(x, y, 0);
Your answer
Follow this Question
Related Questions
Line render from an object to a click 0 Answers
Line renderer rotation and alignment 1 Answer
how to find a point(vector2) between two points(Vector2) of a line (line renderer) 2 Answers
Change Script so that the object's position can be modified in the Editor/through other scripts? 1 Answer
How to diappear a line renderer from start and end position of line 1 Answer