Moving child of gameObject

So I have a Canvas GameObject, which is dragged to the inspector on my scripted camera.

    public GameObject Canvas2_redline_menu;

How to translate (change x/y position) of the “Group0” which is under the Canvas? Group0 is an Empty that contains the buttons.

Here is my non-working attempt…

Canvas2_redline_menu.GetComponent<Group0>.transform = new Vector2(interaction_mousepos_x, interaction_mousepos_y);

thanks,

Propably something simple:

.transform =

// Change to:
.transform.position =
1 Like

I am getting errors:

‘GameObject.GetComponent()’ is a method, which is not valid in the given context

The type or namespace name ‘Group0’ could not be found (are you missing a using directive or an assembly reference?)

“Group0” is a class? or the name of the child under the canvas?

Group0 is the name of the child under the canvas. It is an “empty” node with the buttons underneath that.

I would like to move the Group0 transform so that all the buttons move together. thanks

GetComponent<>() gets a component on the specified gameobject. You’re looking for the transform of a seperate gameobject…

If there is only one child you could use

transform.GetChild(0)

if there are multiple children you’re likely either going to need to specify a reference in the inspector to the right one, or iterate over all children looking for name/attachedcomponent/something

It works wonderfully, thanks a lot.

Canvas2_redline_menu.transform.GetChild(0).GetComponent<Transform>().position = new Vector2(interaction_mousepos_x, interaction_mousepos_y);