Files
Nydaliv/Assets/Imported/Scripts/RectTransformExtensions.cs
2020-02-03 00:21:00 +00:00

28 lines
758 B
C#

/*
* @author Eldoir
* @link https://answers.unity.com/questions/888257/access-left-right-top-and-bottom-of-recttransform.html#
*/
using UnityEngine;
public static class RectTransformExtensions
{
public static void SetLeft(this RectTransform rt, float left)
{
rt.offsetMin = new Vector2(left, rt.offsetMin.y);
}
public static void SetRight(this RectTransform rt, float right)
{
rt.offsetMax = new Vector2(-right, rt.offsetMax.y);
}
public static void SetTop(this RectTransform rt, float top)
{
rt.offsetMax = new Vector2(rt.offsetMax.x, -top);
}
public static void SetBottom(this RectTransform rt, float bottom)
{
rt.offsetMin = new Vector2(rt.offsetMin.x, bottom);
}
}