【Unity】UGUI怎么计算RectTransform中的Top和Bottom的值

来源:互联网 发布:微擎人人商城源码下载 编辑:程序博客网 时间:2024/05/21 09:22

这个是我在使用UGUI中最蛋疼的一个属性,它明明就在那里,但是你却无法调用.....

所以所以所以,我查了和试了它的好多方法,终于解决了......希望对大家有所帮助

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 () {// max.y返回的偏移量是个负数,所以需要乘以-1Debug.Log("Top" + ":" + mySprite.offsetMax.y * -1);Debug.Log("Bottom" + ":" + mySprite.offsetMin.y );}}


0 0
原创粉丝点击