【问题标题】:How to find the mouse position in Unity using the New Input System如何使用新的输入系统在 Unity 中查找鼠标位置
【发布时间】:2021-04-03 10:23:38
【问题描述】:

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

InputDevice mouse = Mouse.current;

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

,但它没有工作。有人吗?

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    使用这个:

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

    【讨论】:

    • 谢谢,但现在我的 Physics.Raycast 没有引用我的光线投射:if (Physics.Raycast(ray, out hit)) { navMeshAgent.SetDestination(hit.point); }
    • @galdeeb-dev 我想答案想说的是:在您的代码中只需将 mouse.position 替换为 mouse.position.ReadValue()
    • 是的,按照@derHugo 的建议编辑了答案。
    • 鼠标不存在
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-31
    • 2020-08-30
    • 2022-07-20
    • 2022-07-06
    • 1970-01-01
    相关资源
    最近更新 更多