首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尽管父比例为x100,但实例化的预置很小

尽管父比例为x100,但实例化的预置很小
EN

Stack Overflow用户
提问于 2015-02-05 17:52:06
回答 3查看 3.3K关注 0票数 1

这简直要把我逼疯了!这就是发生的事情,我就是不明白

在编辑器中,我的父对象的比例为100,100,100

预置的变换如下所示:

代码语言:javascript
复制
Position: 0, -1.939, 0 Rotation: 0, 0, 0 Scale: 0.3946165, 0.3946165, 0.3946165

如果我把它拖到父级,它看起来很完美,就像我想要的那样。

我将预置导出为AssetBundle,并在运行时导入,如下所示:

代码语言:javascript
复制
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

如果我在应用程序中包含孩子,并简单地设置活动,打开或关闭孩子看起来很完美,它只在实例化时才会着色,这是我需要在运行时导入模型的一个功能……

EN

回答 3

Stack Overflow用户

发布于 2015-02-05 18:21:08

当您重新设定对象的父对象时,其世界比例保持不变。这意味着它的局部规模发生了变化。因此,如果您知道在重新设置为父对象之后希望它的本地比例是什么,那么应该在重新设置为父对象之后设置它的本地比例。

票数 1
EN

Stack Overflow用户

发布于 2015-02-05 18:23:48

应先设置参数,然后再设置比例。

切换以下行:

代码语言:javascript
复制
currentPerson.transform.localScale = new Vector3(300, 300, 300);
currentPerson.transform.parent = GameObject.Find("PeopleImageTarget").transform;

尝试:

代码语言:javascript
复制
currentPerson.transform.parent = GameObject.Find("PeopleImageTarget").transform;
currentPerson.transform.localScale = new Vector3(300, 300, 300);
票数 0
EN

Stack Overflow用户

发布于 2015-02-06 04:02:41

要在更改父对象时保留缩放(或不保留),请根据需要使用Transform.SetParent并设置worldPositionStays参数:

代码语言:javascript
复制
Transform targetTransform = GameObject.Find("PeopleImageTarget").transform;
currentPerson.transform.SetParent(targetTransform, true);

请注意,这需要Unity 4.6或更高版本。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28340831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档