- Home /
UI How to configure Left And Right.
Hi,
How to configure via script, the variables 'left' and 'right'?
I created a dynamic list that creates new 'lines' via script, but his position on the screen does not appear the way I want.
Am not quiet sure what exactly you are trying to achieve here. Can you post your script?, It would be easier this way as to figure out what exactly you are doing!
Answer by Scribe · Dec 22, 2014 at 11:57 AM
personally I like to do it by setting the anchor points and then setting the offset positions which is what I have done in the example code, I believe you can also set the anchor points, then set the pivot point and then set the sizeDelta if you want to base you positions more on percentage of screen size rather than pixel size. Have a read of this page for some more details!
public RectTransform this_rect;
public float left = 1f;
public float right = 1f;
public float posY = -50f;
public float height = 50f;
void Update(){
this_rect.anchorMin = new Vector2(0, 1);
this_rect.anchorMax = new Vector2(1, 1);
Vector2 temp = new Vector2(left, posY-(height/2f));
this_rect.offsetMin = temp;
temp = new Vector3(-right, temp.y+height);
this_rect.offsetMax = temp;
}
remember to use the UnityEngine.UI library at the top of your script!
Scribe
Your answer
Follow this Question
Related Questions
How to change the Top and Bottom (rect.yMin and yMax) properties of a rectTransform, in a script? 2 Answers
Change size of the new UI rect transform using scripts 0 Answers
SetAsLastSibling seems to sort alphabetically when used across different objects. 0 Answers
Horizontal Layout Group making a Scroll Rect's Content rect width to be negative 1 Answer
Convert Input.mousePosition to RectTransform pivot position 2 Answers