I have a simple clear 2d scene. There is a Main camera with the strength of 5 and a canvas to hold GUI elements.
I have a script attached to canvas which creates a GameObject and adds a Text component to the Canvase.
Now I would like to position Text inside Canvas. Canvas’ width is 900 of some_units and it takes the whole Camera width (strength is 10 meters).
How do I do it programmaticaly? Don’t quite understand how to convert 900 of some_units (prob pixels) into 10 meters.
EDIT: Added some code
...
RectTransform rectTransform = textGameObject.GetComponent<RectTransform>();
// Put anchor point into left upper corner
rectTransform.anchorMin = new Vector2(0, 1)
rectTransform.anchorMax = new Vector2(0, 1)
// Put pivot into left upper corner as well
rectTransform.pivot = new Vector2(0, 1)
// Position text at (0, 0) coordinate
textRectTransform.transform.position = new Vector2(0, 0); // doesn't work
textRectTransform.anchoredPosition = new Vector2(0, 0); // doesn't work
textRectTransform.localPosition = new Vector2(0, 0); // doesn't work
...
How the text can be posotioned in the left upper corner as well?
EDIT2: Ok, anchoredTransform actually worked… being called during Start() it didn’t set posotion correctly.