RectTransform的参数获取修改方法

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class RectTransformTest: MonoBehaviour
{

    private RectTransform RT;
    private float top;
    private float bottom;
    private float wight;
    private float height;
    private float x, y, z;

    private void Start()
    {
        RT = transform.GetComponent();

        //改变RectTransform的top
        RT.offsetMax = new Vector2(RT.offsetMax.x, top);

        //改变RectTransform的bottom
        RT.offsetMin = new Vector2(RT.offsetMin.x, bottom);

        //改变RectTransform的width,height
        RT.sizeDelta = new Vector2(wight, height);

        //改变RectTransform的pos
        RT.anchoredPosition3D = new Vector3(x, y, z);

        RT.anchoredPosition = new Vector2(x, y);
    }
}

 

欢迎加群:4364930讨论。

你可能感兴趣的:(UGUI)