修改RectTransform的值


用uGUI的時候。經常需要動態改變RectTransform的值,

 

當選擇不同的布局。你會發現這里的值是不同的

有的left,botom。或者posx posy

 

這時想改變就要通過對應的屬性值了

U3D 新UI系統UGUI 的recttransform一些參數的設置
unity出了一套比之前好用的UI系統,但是也新出了RectTransform,PosX,PosY....,剛開始可能不知道怎么用代碼去更改,但是經過許多的實驗之后就會明白一些:


1.改變RectTransform的top
GetComponent<RectTransform>().offsetMax = new Vector2(GetComponent<RectTransform>().offsetMax.x, top);


2.改變RectTransform的bottom
GetComponent<RectTransform>().offsetMin = new Vector2(GetComponent<RectTransform>().offsetMin.x, bottom);


3.改變RectTransform的width,height
GetComponent<RectTransform>().sizeDelta = new Vector2(width, height);


4.改變RectTransform的pos
GetComponent<RectTransform>().anchoredPosition3D = new Vector3(posx,posy,posz);
GetComponent<RectTransform>().anchoredPosition = new Vector2(posx,posy);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM