I'm trying to instantiate an object (A) as a child of a canvas.
The position of A is set using a B object's position, also a child of the Canvas.
Not sure if this is useful for my question, but A and B both have a child.
When I spawn A, it's position is not B's position at all, even if my
GameObject Laser_Projectile = Instantiate(Resources.Load("Sprites/Object_Laser_Projectile") as GameObject);
this.transform.localPosition = GameObject.Find("Player_Objects").transform.localPosition;
You are setting the
localPosition of the transform, this sets it relative to its parent, but you are setting it to an unrelated object's localPosition instead of its global position (
transform.position), which will end up being incorrect. In this case, you can compare the parent's world position to the other object's world position like so
Vector3 thePos = this.transform.parent.position - GameObject.Find("Player_Objects").transform.position;
Then you can set the
localPosition of the object using this new
this.transform.localPosition = thePos;