您的位置:首页 > 产品设计 > UI/UE

【学习笔记】NGUI中实例化预设物体的位置问题

2016-01-05 17:02 399 查看
遇到的问题:

在使用NGUI时希望在脚本中动态实例化一些范例UI组件,但发现实例化之后组件的位置会自动改变,尝试使用trasform.postion手动设定物体的位置,但得出的结果却不正确。

分析:

在NGUI使用Instantiate实例化物体都是以NGUI的摄像机为基础的,所以不能使用trasform.postion,而改为trasform.localPostion,即可。

解决方法:

for(int i=0; i<10; i++)
{
GameObject fileObj = new GameObject();
fileObj = Instantiate(file) as GameObject;
fileObj.transform.parent = this.transform;
fileObj.transform.localPosition = new Vector3(0,-42-i*38,0);
fileObj.transform.localScale = new Vector3(1,1,1);
}


另:该贴中提出了另一种方法,但我没有去尝试
http://www.ceeger.com/forum/read.php?tid=16745
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Unity ngui 实例