Unity如何修改UGUI下组件的长度和宽度,之前一直没用过,现在才知道的(用的5.3.2版本)。

只有一句话: this.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(200F,100F);

具体例子:更多内容请关注微信公众号:unity风雨路

在ugui里建立一个image图片:

默认大小为100*100我们要动态改为200*100

Unity如何修改UGUI下组件的长度和宽度_默认大小

只用下面代码:

 

using UnityEngine;
using System.Collections;

public class TESTPOS : MonoBehaviour {

// Use this for initialization
void Start () {

this.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(200F,100F);
}

// Update is called once per frame
void Update () {

}
}

然后看效果:

 

Unity如何修改UGUI下组件的长度和宽度_System_02