【发布时间】:2018-07-10 08:45:57
【问题描述】:
我有一个简单的库存系统,其中 Canvas 设置为屏幕空间 - 相机。 出于某种原因,将图标设置为 vector3.zero 会使它们转到其他位置。
第一张图片正在启动,一切正常。
第二张图片是被拖动的苹果,你可以看到位置是正确的
一旦掉下来,就可以看到苹果去了一个未知的地方。
这是 endDrag 的代码:
public void OnEndDrag(PointerEventData eventData)
{
if (item.category != ITEM_CATEGORY.Voxel)
{
icon.transform.position = Vector3.zero;
}
else
{
cube.transform.position = Vector3.zero;
}
}
没有什么独特的。
这里是拖动事件:
public void OnDrag(PointerEventData eventData)
{
if (item.category != ITEM_CATEGORY.Voxel)
{
Vector3 screenPoint = Input.mousePosition;
screenPoint.z = 0.13f; //distance of the plane from the camera
icon.transform.position = Camera.main.ScreenToWorldPoint(screenPoint);
}
else
{
Vector3 screenPoint = Input.mousePosition;
screenPoint.z = 0.13f; //distance of the plane from the camera
cube.transform.position = Camera.main.ScreenToWorldPoint(screenPoint);
}
}
【问题讨论】:
-
“出于某种原因,将图标设置为 vector3.zero 时会使它们转到
somewhere else” - 可能是原点? -
origin 应该是 0,0,0,这是它们的正确位置
-
什么更可能?
vector3.zero的实现中存在错误,实际上只是vector3(0, 0, 0)的简写,或者您的代码中存在错误? -
你的代码是罪魁祸首。 Vector3 不能被“窃听”:Reference
标签: c# visual-studio unity3d