One can easily change RectTransform right,left,top and bottom value using script in this way :-
object.GetComponent<RectTransform> ().offsetMin = new Vector2 (0,-1);//left-bottom
here "0" indicates Left value and "-1" indicates bottom value.
Similarly for setting Right and Top value use:
object.GetComponent<RectTransform> ().offsetMax = new Vector2 (0,1);//right-top
here "0" indicating Right value and "1" indicating Top value.
In my case value is 0 or 1. But it can be any value rather than 0 or 1.
e.g:-
object.GetComponent<RectTransform> ().offsetMin = new Vector2 (10,12);//left-bottom
object.GetComponent<RectTransform> ().offsetMax = new Vector2 (20,40);//right-top
For more understanding :-
- rectTransform.offsetMin.x // Left
- rectTransform.offsetMin.y // Bottom
- rectTransform.OffsetMax.x // Right
- rectTransform.offestMax.y // Top
Hopefully this will be helpful for you.
Thanks!
0 Comment(s)