您的位置:首页 > 移动开发 > Unity3D

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

2015-09-29 18:03 801 查看
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);

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: