这简直要把我逼疯了!这就是发生的事情,我就是不明白
在编辑器中,我的父对象的比例为100,100,100
预置的变换如下所示:
Position: 0, -1.939, 0 Rotation: 0, 0, 0 Scale: 0.3946165, 0.3946165, 0.3946165如果我把它拖到父级,它看起来很完美,就像我想要的那样。
我将预置导出为AssetBundle,并在运行时导入,如下所示:
currentPerson = Instantiate(bundle.mainAsset,new Vector3(0, -1.939f, 0), Quaternion.identity) as GameObject;
currentPerson.transform.localScale = new Vector3(300, 300, 300);
currentPerson.transform.parent = GameObject.Find("PeopleImageTarget").transform;
Debug.Log(currentPerson.transform.position.x + ", " + currentPerson.transform.position.y + ", " + currentPerson.transform.position.z);
Debug.Log(currentPerson.transform.rotation.x + ", " + currentPerson.transform.rotation.y + ", " + currentPerson.transform.rotation.z);
Debug.Log (currentPerson.transform.localScale.x + ", " + currentPerson.transform.localScale.y + ", " + currentPerson.transform.localScale.z);现在,子对象出现了,但它仍然很小,我将scale设置为300以尝试增加它的大小,它在调试日志中报告为3
这是一个导出到IOS的应用程序,使用了Vuforia的增强现实工具,因此父比例为100
如果我在应用程序中包含孩子,并简单地设置活动,打开或关闭孩子看起来很完美,它只在实例化时才会着色,这是我需要在运行时导入模型的一个功能……
发布于 2015-02-05 18:21:08
当您重新设定对象的父对象时,其世界比例保持不变。这意味着它的局部规模发生了变化。因此,如果您知道在重新设置为父对象之后希望它的本地比例是什么,那么应该在重新设置为父对象之后设置它的本地比例。
发布于 2015-02-05 18:23:48
应先设置参数,然后再设置比例。
切换以下行:
currentPerson.transform.localScale = new Vector3(300, 300, 300);
currentPerson.transform.parent = GameObject.Find("PeopleImageTarget").transform;尝试:
currentPerson.transform.parent = GameObject.Find("PeopleImageTarget").transform;
currentPerson.transform.localScale = new Vector3(300, 300, 300);发布于 2015-02-06 04:02:41
要在更改父对象时保留缩放(或不保留),请根据需要使用Transform.SetParent并设置worldPositionStays参数:
Transform targetTransform = GameObject.Find("PeopleImageTarget").transform;
currentPerson.transform.SetParent(targetTransform, true);请注意,这需要Unity 4.6或更高版本。
https://stackoverflow.com/questions/28340831
复制相似问题