- Home /
UI Element Transform being set incorrectly
public void InstallButton(HUDButton button) {
GameObject btnObject = Instantiate (button.gameObject);
btnObject.transform.SetParent (gameObject.transform);
Vector2 pos = new Vector2 (button.PreferredIndex () * 85f, -32.5f);
btnObject.transform.position = pos;
}
I am able to see that pos
below is the value that I expect, but the object that I believe to be affected by this function in the scene has a different transform position than this value. Is there some order of operations or lifecycle circumstances that I'm not taking into account? Is there any other information that I'm just totally missing?
NOTE: This is a UI component and so I understand that this might have different vector space?
Answer by YoucefB · Oct 10, 2017 at 04:15 PM
You need to set the Transform.localPosition instead if you want your ui element's position to be relative to its parent position.
btnObject.transform.localPosition = pos;
Annoyingly, that doesn't seem to affect the behavior at all. It's possible I'm not setting something else up. If it helps, the "parent" has a bottom-left anchor point
Your answer

Follow this Question
Related Questions
UI objects move at different speeds on different resolutions 1 Answer
Move UI element towards direction it is facing 0 Answers
UI Buttons dont react on click 4 Answers
Image with transparency cut-offs as button 2 Answers
I'm trying to make a UI object move from one position to another over time 0 Answers