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

来源:互联网 发布:h3c 端口聚合配置 编辑:程序博客网 时间:2024/06/04 00:20

遇到的问题:

在使用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

0 0
原创粉丝点击