unity, 动态创建节点时一定要先指定父节点再设置transform
2015-12-23 16:17
585 查看
如下,设置transform的代码必须放在node.transform.parent=transform之后。否则设置将不生效。
GameObject node = new GameObject ();
node.name=”myNode”;
node.transform.parent = transform;
node.transform.localScale = new Vector3 (1, 1, 1);
node.transform.localPosition = new Vector3 (0, 0, 0);
node.transform.localRotation = Quaternion.identity;
更新(2015-8-7):
细看了一下,控制台有个warning:
Parent of RectTransform is being set with parent property. Consider using the SetParent method instead, with the worldPositionStays argument set to false. This will retain local orientation and scale rather than world orientation and scale, which can prevent common UI scaling issues.
所以,应该写成下面这样才是标准的:
GameObject node = new GameObject ();
node.name=”myNode”;
node.transform.SetParent(transform,false);
node.transform.localScale = new Vector3 (1, 1, 1);
node.transform.localPosition = new Vector3 (0, 0, 0);
node.transform.localRotation = Quaternion.identity;
GameObject node = new GameObject ();
node.name=”myNode”;
node.transform.parent = transform;
node.transform.localScale = new Vector3 (1, 1, 1);
node.transform.localPosition = new Vector3 (0, 0, 0);
node.transform.localRotation = Quaternion.identity;
更新(2015-8-7):
细看了一下,控制台有个warning:
Parent of RectTransform is being set with parent property. Consider using the SetParent method instead, with the worldPositionStays argument set to false. This will retain local orientation and scale rather than world orientation and scale, which can prevent common UI scaling issues.
所以,应该写成下面这样才是标准的:
GameObject node = new GameObject ();
node.name=”myNode”;
node.transform.SetParent(transform,false);
node.transform.localScale = new Vector3 (1, 1, 1);
node.transform.localPosition = new Vector3 (0, 0, 0);
node.transform.localRotation = Quaternion.identity;
相关文章推荐
- unity3d easytouch计算摇杆旋转角度以及摇杆八方向控制角色
- Unity3d地图制作之模型高光
- [Unity] 从SurvivalShooter的角色移动,看FixedUpdate与Update
- 【Unity Tips】备忘录(扫盲篇)
- Unity3D圆滑旋转物体
- unity3d-准备工作 - VS2013
- Unity3d打包发布Android程序
- Unity3D游戏开发之小地图的实现
- [Unity3D]Unity3D游戏开发之角色控制漫谈
- (转)unity中基于alpha通道的shadow volume实现
- Unity3D NGUI自适应屏幕分辨率
- Unity3D 控制物体移动、旋转、缩放
- unity3D让物体惯性的旋转
- Unity3D研究院之主角面朝方向一定区域内对象角度计算
- Unity3D与旋转相关的函数(C#)
- Unity3D研究院之主角面朝方向一定区域内对象角度计算
- unity3d easytouch计算摇杆旋转角度以及摇杆八方向控制角色
- 在Unity3D中加载外部图片的两种方法
- Unity3D游戏内存瘦身 UI优化是关键
- Unity3D 中 用quaternion 来对一个坐标点进行旋转的初步体会