- Edited
[SOLVED]
I have a CanvasLayer as root of my GUI who I create from C#.
The first GUI that I create is correctly positioned, but when I want to add a second Control which must be centered on the screen it is not centered correctly.
The first GUI :
The second Control :
Like you can see, the top left corner of the new Control is correctly centered but that's not what he's supposed to do.
If I change the preset from the editor while it's running and set it back to Center, the position is corrected :
But if I try to do it from script it won't work (or I don't know how exactly I need to do it)
It's as if it was positioned in the center of the screen with a size of 0 and then resized (once its content has been calculated) relative to its upper left corner so everything is shifted to the right.
What can I do to resolve this ?
[EDIT]
The Solution was grow_horizontal
and grow_vertical
who have to be set to Control.GrowDirection.Both
.
Like this :
myControl.GrowHorizontal = Control.GrowDirection.Both;
myControl.GrowVertical = Control.GrowDirection.Both;
As I don't see these values in the inspector, I didn't know they existed, especially since when the changes were made in the editor, the problem did not appear.