我们如何在统一 3D 中将两个移动到一起? [英] How we can move two together in unity 3D?

查看:19
本文介绍了我们如何在统一 3D 中将两个移动到一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上我想将两个子对象相互连接,这样当一个对象的大小增加时,两个对象应该一起移动并改变其位置.我想在预制件中做到这一点可以吗?

Actually I want to connect two child object with each other, so that when size increase of one object both the object should be moved together and change its position. I want to do this in prefab is it possible ?

这是层次结构截图:

基本上我想增加玻璃的大小(side1_screen1 的子对象),但随着玻璃的增加,我的支持(子对象)的大小也在增加.

Basically I want to increase size of glass (child object of side1_screen1) but along with glass, my support(child object) its size is also increasing.

但是当我单独增加玻璃尺寸时,我的支撑位置不会改变,所以当玻璃尺寸增加时可以使用的任何方法,我的支撑尺寸都不应该增加.

But when individually I increase size of glass my support position is not changing, so any approach that can be used when glass size increases, my support size should not increase.

任何方法将不胜感激.提前致谢.

Any approach will be appreciated. Thanks in advance.

推荐答案

我不知道这是否是您的要求,但您可以简单地连接";通过将多个子对象作为同一个对象的父对象.在这个例子中,我简单地创建了两个子对象和一个空的 GameObject 作为容器.每当您缩放、旋转或移动容器时,子对象都会这样做.

I do not know if this is what you are asking for, but you can simply "connect" multiple child objects by parenting them to the same object. In this example, I have simply created two child objects and an empty GameObject as container. Whenever you scale, rotate or move the container, the child objects will do the same.

在层次结构中,您不能连接";多个子对象相互关联,而不会将其中一个对象设为父对象.

In the hierarchy, you cannot "connect" multiple child objects to each other without also making one of them a parent.

您可以尝试的另一种(快速而肮脏的)方法是创建一个脚本,该脚本引用两个游戏对象的变换组件,然后根据另一个设置其中一个.

Another (quick and dirty) approach you could try is to create a script that references the transform component of both GameObjects and then sets one of them according to the other.

你可以把它放在你的 Update() 方法中:

You can place this inside your Update() method:

firstChild.transform.position = secondChild.transform.position + Vector3 offsetValue (otherwise they will be in the same position)

firstChild.transform.rotation = secondChild.transform.rotation

firstChild.transform.localScale = secondChild.transform.localScale

在您创建脚本并根据自己的喜好引用所有内容后,您只需将父对象拖到您的项目文件夹之一中即可使其成为预制件.

After you've created your script and referenced everything to your liking, you can simply drag the parent object into one of your project folders to make it a prefab.

这篇关于我们如何在统一 3D 中将两个移动到一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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