【Unity】UGUI中RectTransform中Top和Bottom的设置,宽和高的设置,以及postion和锚点的设置
UGUI中RectTransform中Top和Bottom的设置,宽和高的设置,以及postion和锚点的设置
using UnityEngine; using System.Collections; using UnityEngine.UI; /// <summary> /// 脚本位置:UGUI的图片 /// </summary> public class test : MonoBehaviour { // 你的图片 private RectTransform mySprite; void Start () { mySprite = gameObject.GetComponent<RectTransform> (); } void Update () { // 1.图片的Top设置为100(偏移的Max是负数) GetComponent<RectTransform> ().offsetMax = new Vector2 (GetComponent<RectTransform> ().offsetMax.x, -100); // 2.图片的Bottom设置为120 GetComponent<RectTransform> ().offsetMin = new Vector2 (GetComponent<RectTransform> ().offsetMin.x, 120); // 3.改变RectTransform的宽和高(注:测试的时候锚点中不要选择带蓝色线的适配方式,那样会被拉伸的) GetComponent<RectTransform> ().sizeDelta = new Vector2 (100, 200); // 4.改变RectTransform的postion(x,y,z) GetComponent<RectTransform> ().anchoredPosition3D = new Vector3 (70 ,80, 90); // 5.改变锚点的位置 GetComponent<RectTransform> ().anchoredPosition = new Vector2 (posx, posy); } }
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: Unity3D 中改变模型的锚点
- 下一篇: 【UGUI】代码设置锚点