【Unity】UGUI中RectTransform中Top和Bottom的设置,宽和高的设置,以及postion和锚点的设置

来源:互联网 发布:linux里sort怎么用 编辑:程序博客网 时间:2024/06/14 06:31

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设置为120GetComponent<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);}}


0 0
原创粉丝点击