anchoredposition 的原點是元素本身的 anchor
vector2 temp =
getcomponent
<
recttransform
>()
.anchoredposition;
getcomponent
<
recttransform
>()
.anchoredposition =
newvector2
(temp.x, temp.y +
50f)
;
posetion是相對於螢幕
vector2 temp =
getcomponent
<
transform
>()
.position;
getcomponent
<
transform
>()
.position =
newvector2
(temp.x, temp.y +
50f)
;
vector2 temp =
getcomponent
<
transform
>()
.localposition;
getcomponent
<
transform
>()
.localposition = vector2.one;
posetion是以世界座標系原點(0,0,0)為中心點,可以理解為絕對座標
vector3 temp =
getcomponent
<
transform
>()
.position;
getcomponent
<
transform
>()
.position = vector3.zero;
localposetion是以父物體為中心,可以理解為相對座標
vector3 temp =
getcomponent
<
transform
>()
.localposition;
getcomponent
<
transform
>()
.localposition =
newvector3
(temp.x, temp.y -
50f,0)
;
unity獲取場景中物體的幾種方式
在編輯 時,需要獲取場景中的物體和元件,對於不同的情況有不同的方法 當 在物體上時,可以直接使用gameobject和transform等方法,獲取該物體的元件為 使用或者不使用 this gameobject.getcomponent 元件名字 獲取子物體和子物體可以使用的有下面幾種 1,使用ge...
Unity 一鍵替換場景中的物體
實現場景中批量替換預製體的編輯器功能。一 關鍵api prefabutility.instantiateprefab 將預設例項化到場景中,與gameobject.instantiate不同,它是以預設例項的。二 工具截圖 三 使用方法 在project中拖拽預設到工具中 開啟需要操作的場景,可以多...
Unity中的物體移動
1 直接改變物體的位置。例子 transform.position transform.position 某一三維向量 vector3 2 public void translate vector3 translation 物體在對應的座標系中,向引數的方向移動,每一幀移動引數大小 引數 trans...