[英]Rotate empty object around center
I manually (from editor) create empty object with boxes. 我手动(从编辑器)创建带有框的空对象。 It rotate around center.
它绕中心旋转。 But if I create same object with boxes from script.
但是,如果我使用脚本中的框创建相同的对象。 It rotate around unknown point for me.
对我来说,它绕着未知的点旋转。 I found the cause.
我找到了原因。 It happening because boxes has scale (0.1, 0.2, 0.1).
发生这种情况是因为盒子的比例为(0.1,0.2,0.1)。 If I set (1,1,1) - it work.
如果我设置(1,1,1)-它可以工作。 How to fix it?
如何解决? I want small boxes.
我要小盒子。
var wall = new GameObject();
//wall.transform.parent = room.transform;
wall.transform.name = "Wall";
wall.transform.position = new Vector3(0,0,0);
for (int x = -3; x < width-3; x++)
{
for (int y = -3; y < height-3; y++)
{
var plate = Instantiate(SimplePlate);
var pos = plate.transform.position;
float posZ = pos.z - (x * plate.transform.lossyScale.z);
float posY = pos.y + (y * plate.transform.lossyScale.y);
var newPos = new Vector3(0, posY, posZ);
plate.transform.position = newPos;
plate.transform.parent = wall.transform;
plate.name = "Plate " + x;
}
}
You could create another empty GameObject and stuff your box inside. 您可以创建另一个空的GameObject并将其填充到其中。 Then rotate the parent you just created?
然后旋转刚刚创建的父级?
Also, how can you rotate an object with a scale of (0,0,0). 另外,如何旋转比例为(0,0,0)的对象。 Did you mean (1,1,1)?
您是说(1,1,1)吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.