Transform position of child is way off.

Hi.
This is my code

      public GameObject prefabHealthBar;

 private void Start()
    {
        GameObject HealthBar = Instantiate(prefabHealthBar) as GameObject;
        HealthBar.transform.parent = transform;
        HealthBar.transform.position = new Vector3(0,1,0);
    }

so I have a prefab of a healthbar that I want to follow my enemies above their head.

in my world I have enemies placed alreday. Lets take Enemy1.

It has transform pos of X= 5, Y= 0, Z= 0.

Now when I press play and the healthbar spawns in from code it should be at transform 0,1,0 (just above the enemy head, problem is my healthbar spawns with a

transform pos of X= -5, Y= 1, Z= 0.

This makes the healthbar appear way to the side of my enemy. How can I fix this?

Found the solution to this. All I did was change this code

   HealthBar.transform.position = new Vector3(0, 1, 0);

   HealthBar.transform.localPosition = new Vector3(0, 1, 0);

to the second version.
:smiley: