Search Unity

Created prefab follows player instead of being fixed to the world

Discussion in '2D' started by JUGoWATER, Jul 15, 2021.

  1. JUGoWATER

    JUGoWATER

    Joined:
    Jul 15, 2021
    Posts:
    2
    I'm instantiating a health bar prefab and it loads into the scene perfectly fine but it moves relative to my player object. I need it to spawn at a static location/position in the world. It is also inside a canvas.


    private void OnMouseDown()
    {
    GameObject hb = Instantiate(HealthBarPrefab, new Vector3(50, 50, 0), Quaternion.identity);

    hb.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform, false);
    }


    upload_2021-7-15_3-20-44.png

    Is there something wrong with this part of the script that would make it move relative to the player?
     

    Attached Files:

  2. Epsilon_Delta

    Epsilon_Delta

    Joined:
    Mar 14, 2018
    Posts:
    258