RectTransform的参数获取修改方法
程序员文章站
2024-02-18 18:17:16
...
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>();
//改变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);
}
}