最适合(放置)长方体对象而不是C#/ unity中的另一个长方体对象

时间:2019-09-06 01:36:50

标签: c# unity3d

在场景中,有12个已知边和8个点。这个形状就像长方体,所以,我有另一个预制件,另一个长方体。我想将我的长方体预制件和另一个旧的长方体放在相同的方向,相同的位置,相同的比例和相同的旋转位置。

https://cdn1.imggmi.com/uploads/2019/9/6/955065f84b3c3ae442f0be8a3e2ee48d-full.png

第一个长方体在运行时创建,命名为referenceCuboid 新对象在我的名为cuboidObj的预制件中

我在edge的帮助下找到了位置。然后将对象放置到referenceCuboid的中心。

{  
    Vector3 position = new Vector3(x, y, z);


    //rotation
    Quaternion rotation = cuboidObj.transform.rotation;
    Quaternion.LookRotation(edgeX.transform.position); //edges are a Cylinder

    cuboidObj.transform.rotation = rotation;

    //Scale
    Vector3 size = obj.transform.lossyScale;

    // (edgeX, edgeY, edgeZ) are reference edges in referenceCuboid
    size.z = edgeZ.transform.lossyScale.z;
    size.x = (size.z* obj.transform.localScale.y) / obj.transform.lossyScale.x;
    size.y = (size.z* obj.transform.localScale.y) / obj.transform.lossyScale.y;
    size.z = (size.z* obj.transform.localScale.y) / obj.transform.lossyScale.z;
    cuboidObj.transform.localScale = size;


    obj.transform.localScale = size;

    cuboidObj = Instantiate(cuboidObj, position, Quaternion.identity);

}

我无法缩放,将新的长方体对象旋转到referenceCuboid。我尝试了新的长方体对象的x y z边缘和x,y,z轴,但没有正确的结果。对齐错误

0 个答案:

没有答案