【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); } }
相关文章推荐
- [Unity3D学习]3D数学基础之坐标系
- 【Unity】UGUI怎么计算RectTransform中的Top和Bottom的值
- Unity 5.x的专用插件推荐
- Unity5 如何做资源管理和增量更新
- Unity抛物线AddForce计算
- Unity笔记 2D Best Practices (2D IK 骨骼动画 event 换装 蒙皮 排序)
- Unity3d:NGUI所见即所得之UIWidget , UIGeometry & UIDrawCall
- Unity5的AssetBundle的一点使用心得
- Unity3d中对应各平台Path
- ubuntu 14.04无法进入unity
- Unity3d NGUI的UILabel中文字体及可点击的字体
- Unity中SpriteRender实现广告牌效果
- Unity使用中间层分发消息通知
- unity3d 打组后的预设体Prefabs 无法触发鼠标点击事件
- unity3D实际的原始视频游戏开发系列讲座12之U3D的2D为了开发实战的新方法
- Unity3D 模型分块
- 【Unity3D游戏开发学习笔记】(三)移山倒海—Terrain的建造
- Unity-EasyTouch插件之ReservedArea的运用(主要是避免JoyStick与Touch的矛盾)
- Unity-EasyTouch插件之ReservedArea的运用(主要是避免JoyStick与Touch的矛盾)
- unity 中读取文本中的物品信息