Kekora
August 23, 2016, 10:31am
1
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,
Zaflis
August 23, 2016, 10:51am
2
Propably something simple:
.transform =
// Change to:
.transform.position =
1 Like
Kekora
August 23, 2016, 11:16am
3
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?
Kekora
August 23, 2016, 11:57am
5
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
Kekora
August 23, 2016, 1:09pm
7
It works wonderfully, thanks a lot.
Canvas2_redline_menu.transform.GetChild(0).GetComponent<Transform>().position = new Vector2(interaction_mousepos_x, interaction_mousepos_y);