unity 修改RectTransform

public class RectCtrl : MonoBehaviour
{
    private void Start()
    {
        var imgRect = GetComponent<RectTransform>();

        /*imgRect.localScale = Vector3.one * 2;
        imgRect.localRotation = Quaternion.Euler(Vector3.forward*45f);
        imgRect.pivot = new Vector2(0, 0);
        imgRect.anchorMin = new Vector2(0.1f, 0.1f);
        imgRect.anchorMax = new Vector2();
        imgRect.anchoredPosition3D = new Vector3(-100, -50, 0);
        imgRect.sizeDelta = new Vector2(50, 50);*/

        imgRect.anchorMin = new Vector2(1, 0.5f);
        imgRect.anchorMax = new Vector2(1, 0.5f);
    }
}

offsetMin : 对应Left、Bottom
offsetMax : 对应Right、Top

  this.transform.GetComponent<RectTransform>().offsetMax = new Vector2(0,0);
  this.transform.GetComponent<RectTransform>().offsetMin = new Vector2(0, 0);

转载地址:Unity 修改RectTransform的值_Sky.Allen的博客-CSDN博客

猜你喜欢

转载自blog.csdn.net/qq_37524903/article/details/130244336