我有一个InputAction
回调,在其中记录播放器单击屏幕的位置,但如果单击不是在UI元素上,则仅为。这是我的密码
private void OnPress(InputAction.CallbackContext context)
{
if (!EventSystem.current.IsPointerOverGameObject())
{
this.pressPosition = Mouse.current.position.ReadValue();
}
}
这是正确的工作。然而,我最近更新了我的统一版本,现在每当我点击游戏中的某个地方时,我都会收到这样的警告:
Calling IsPointerOverGameObject() from within event processing (such as from InputAction callbacks)
will not work as expected; it will query UI state from the last frame
根据变化量g,此警告是添加到输入系统的更新中的。
当玩家在没有收到警告的情况下点击屏幕时,是否有一种方法可以判断鼠标是否在UI上?
发布于 2022-08-20 07:55:30
private bool pressControl = false;
private void Update()
{
if (Mouse.current.leftButton.wasPressedThisFrame)
pressControl =!EventSystem.current.IsPointerOverGameObject(PointerInputModule.kMouseLeftId);
}
void selector(InputAction.CallbackContext context)
{
if (!pressControl) return;
pressControl = false;
Vector3 position = new Vector3(mausePositionEvent.ReadValue<Vector2>().x, mausePositionEvent.ReadValue<Vector2>().y, 0);
Ray ray = Camera.main.ScreenPointToRay(position);
RaycastHit hit;
if (!Physics.Raycast(ray, out hit)) return;
}
https://stackoverflow.com/questions/70131228
复制相似问题