昨天我问了一个问题,该问题是关于如何始终使两个对象具有相同的y值。并且它起作用了,但是,我现在发布的是,我需要第二个多维数据集具有相同的y值BUT,且其第一个多维数据集的-Y值比第一个低-0.5个单位。我的原始多维数据集称为“播放器”,而脚本已附加到名为“ TestCube”的多维数据集。谢谢!using UnityEngine;using System.Collections;public class testmovement : MonoBehaviour{ Transform otherTransform; void Start() { // you can set a reference to the "parent" cube otherTransform = GameObject.Find("Player").transform; } void Update() { // here we force the position of the current object to have the same y as the parent transform.position = new Vector3(transform.position.x, otherTransform.position.y, transform.position.z); }}
3 回答

POPMUISE
TA贡献1765条经验 获得超5个赞
您可以在功能参数列表中进行算术运算。所以写
transform.position = new Vector3(transform.position.x, otherTransform.position.y -0.5f, transform.position.z);
您可以实现恒定的Y偏移。

ITMISS
TA贡献1871条经验 获得超8个赞
transform.position = transform.position + new Vector3(0, -0.5f, 0); //Or
transform.position = transform.position - new Vector3(0, 0.5f, 0);

呼唤远方
TA贡献1856条经验 获得超11个赞
您也可以在“检查器”中执行此操作-使用层次结构设置关系Parent-Children(将一个对象放置在另一个对象上),然后将child相对于父位置变换组件IS,以便x:0,y:-0.5,z:0会给您预期的效果。
- 3 回答
- 0 关注
- 213 浏览
添加回答
举报
0/150
提交
取消