Question by
KokodokoGames · Aug 29, 2015 at 11:38 AM ·
vector3transform.positiondepthz
Why does the Z position of my sprite change after updating the X position?
I have a GameObject called Background, with a sprite. The Background has transform 0,0,0 but it sits inside a parent GameObject with transform 0,0,10. This way, everything inside this parent object should always be rendered at Z position 10, or so I thought.
When I update my Background's x position like this:
transform.position = new Vector3(newX, 0f, 0f);
Suddenly the background goes to Z position 0 in the main game as well, even though its parent is still at Z position 10. In other words, game objects at Z : 5 are now suddenly behind the background.
How is this possible? Can't I set a parent GameObject so that all it's children will always be at the Z of its parent?
Comment
change localPosition, not position. position will always alter the position as if the object had no parent.