仅在一侧缩放游戏对象 [英] Scale gameobject on just one side

查看:85
本文介绍了仅在一侧缩放游戏对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将多维数据集添加到场景,并且缩放并放置到位置(0,0,0). 我正在用附加到多维数据集的代码扩展该多维数据集

I have added Cube to scene and I scaled and put to position ( 0, 0, 0 ). I am scaling that Cube with code attached to Cube

IEnumerator Start() {
    StartCoroutine("DoSomething", 2.0F);
    yield return new WaitForSeconds(1);
    StopCoroutine("DoSomething");
}

IEnumerator DoSomething(float someParameter) {
    while (true) {
        transform.localScale += new Vector3(0, 0.1f, 0);
        yield return null;
    }
}

,但是Cube在两侧缩放到顶部和底部.我想使用相同的因子进行缩放,但是Cube的底部保持在相同的位置. 我试图在transform.localScale += new Vector3(0, 0.1f, 0);yield return null;之间设置新位置,但我不知道如何获得确切的金额. (我尝试阅读

but Cube scales on both sides, to top and bottom. I want to scale with same factor but that bottom of Cube stays on same position. I tried to set new position between transform.localScale += new Vector3(0, 0.1f, 0); and yield return null; but I don't know how to get exact amount. ( I tried to read

Mesh planeMesh = gameObject.GetComponent<MeshFilter>().mesh;
        Bounds bounds = planeMesh.bounds;
        bounds.size.y;

缩放前后,并添加到

transform.position.y之间的区别 boundsAfter.size.yboundsBefore.size.y

但是它移动得太多.

如何解决这个问题?

推荐答案

您实际上可以通过两种方式执行此操作.

You can actually do this in two ways.

方法1 :

从外部应用程序更改枢轴点.

Change pivot point from an external application.

在3D软件(例如Maya)中创建一个简单的多维数据集,然后将枢轴点定位到多维数据集的底部,然后将其导出为Unity.这应该是开箱即用的.

Create a simple Cube in a 3D software such as Maya then position the pivot point to the bottom of the cube and then export it Unity. This should work out of the box.

方法2 :

将多维数据集绑定到一个空的GameObject.

Parent the Cube to an empty GameObject.

步骤:

A .创建一个空的GameObject.

A.Create a an Empty GameObject.

B .将新的GameObject移至多维数据集的位置,然后将新的GameObject的y轴移至多维数据集的底部.必须通过放大来精确定位y-pos.有关更多信息,请参见下面的动画.

B.Move the new GameObject to the position of the Cube then move the y axis of that new GameObject to the bottom of the cube. The y-pos must be positioned precisely by zooming in. See to the animation below for more information.

C .现在将 Cube 拖动到该新GameObject,并且该Cube应该是该新GameObject的 child .现在,您可以将问题中的脚本附加到该新的 GameObject 上,它只应在一侧缩放多维数据集.不要忘记删除直接附加到多维数据集的旧缩放脚本.

C.Now drag the Cube to the that new GameObject and the cube should be the child of that new GameObject. You can now attach the script in your question to that new GameObject and it should scale the cube on one side only. Don't forget to remove the old scaling script that is directly attached to the cube.

图像教程.高质量版本此处.

Image Tutorial. High quality version here.

这篇关于仅在一侧缩放游戏对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆