Search code examples
c#unity-game-engine2d

How to apply a offset to child gameobject in Unity2D


I'm trying to apply an offset to a unity child gameobject who's transform component values doesn't change on its own.

I've tried solutions like the pictures show but none of them work how would i apply an offset when facing a certain direction. The weird thing about the Image 1 solution is that its transform position is set to the parents position without any other affecting it. Image 1Image 2 the change numbers or magnitude is just as an example.


Solution

  • Transform.position is a world space position.

    In other words, when you do transform.position = new Vector2(-2, transform.position.y), the -2 is relative to the world center.

    You can use Transform.localPosition for parent-related positioning.