这似乎是一个重复的问题。我有一根钓鱼竿和钓竿末端的钩子。无论我在哪里点击屏幕,根据点击的 y 索引,我将我的钩子移动到那个位置。例如,假设我的钩子当前位于 (2,3),如果我点击 (400, 9),我将钩子移动到 (2,9)。所以我只是根据点击垂直移动它。
这工作正常。现在根据钩子的位置,我想相应地缩放我的钓竿。因此,一旦我完成定位我的钩子,我就会调用以下 ScaleRod()。杆子精灵在左上角有一个枢轴,而不是中心。我只想垂直缩放。以下是我的相同代码:
void scaleRod() {
//get current size of the fishing rod
var rodLength = System.Math.Abs(renderer.bounds.size.y);
//Get distance between the hook and the rod based on y coordinates.
float hookRodDistance = (System.Math.Abs(transform.position.y) + rodLength) - System.Math.Abs(hookObject.transform.position.y);
hookRodDistance = System.Math.Abs(hookRodDistance);
//Calculate the scale factor
float scaleFactor = hookRodDistance / rodLength;
//Scale the rod
transform.localScale = new Vector3(transform.localScale.x, scaleFactor * transform.localScale.y, transform.localScale.z );
}
该功能在规模上给了我奇怪的输出。
有人可以帮忙吗。在这个问题上已经卡了一段时间了。太感谢了。
编辑:添加图像以更好地了解该问题。