我有一个简单的库存系统,画布设置为屏幕空间摄像机。
出于某种原因,当将图标设置为vector3.zero时,会使它们转到其他地方。
下面是一个例子:
第一张图片开始,一切正常。
第二张图片是苹果被拖动,你可以看到位置是正确的。
一旦掉到可以看到的地方,苹果就会去一个未知的地方。
这是enddrag的代码:
public void onenddrag(pointReventData EventData)
{
如果(item.category!=项目\类别.体素)
{
icon.transform.position=vector3.zero;
}
其他的
{
cube.transform.position=vector3.zero;
}
}
没有独特之处。
以下是拖动事件:
public void ondrag(pointReventData EventData)
{
如果(item.category!=项目\类别.体素)
{
vector3屏幕点=input.mouseposition;
screenpoint.z=0.13f;//平面到相机的距离
icon.transform.position=camera.main.screentownorldpoint(屏幕点);
}
其他的
{
vector3屏幕点=input.mouseposition;



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);
}
}