如何检查 Vector3 的 X 或 Y 分量是否增加或减少

How to check if the X or Y component of a Vector3 has increased or decreased

我有一个 Vector3,其中包含有关世界空间中 gameOjects 位置的信息,我想知道是否可以查询 x 和 y 组件以查看它是否已更改?

提前为您的帮助干杯

您可以随时使用 gameObject.transform.position 查询对象的位置,这将为您提供在世界 space 中的位置。如果将该位置保存到变量中,则可以检查它是否以及如何在下一帧中发生变化:

Vector3 oldPosition; // the Vector you want to compare to
Vector3 delta = transform.position - oldPosition; 
// delta now contains how much the position has changed since oldPosition