如何在Unity中使用新输入系统找到鼠标位置

5

我如何在Unity中找到鼠标的位置?我正在使用新输入系统,已经尝试过:

InputDevice mouse = Mouse.current;

Ray ray = camera.ScreenPointToRay(mouse.position);

但它没有起作用。有人知道怎么回事吗?

2个回答

1

use this:

Ray ray = camera.ScreenPointToRay(Mouse.current.position.ReadValue());

谢谢,但现在我的Physics.Raycast没有对我的射线投射的引用:if (Physics.Raycast(ray, out hit)) { navMeshAgent.SetDestination(hit.point); } - galdeeb-dev
@galdeeb-dev,我认为答案想要表达的是:在你的代码中,只需将 mouse.position 替换为 mouse.position.ReadValue() - derHugo
是的,已经按照@derHugo的建议编辑了答案。 - Mahsa
4
鼠标不存在。 - pete

0
using UnityEngine.InputSystem;


float mouseX = Mouse.current.position.x.ReadValue();
float mouseY = Mouse.current.position.y.ReadValue();
Ray ray = camera.ScreenPointToRay(new Vector3(mouseX, mouseY, 0));

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接