unity3d - 触摸UI时防止移动的方法?
问题描述
随着时间的推移,当我触摸到某个点时,我想移动我的角色。但如果触摸点是 UI 元素,我不希望它定位。我通过鼠标单击 PC 来实现这一点,但在 Android 上却没有。
PC鼠标点击没有问题:
if (Input.GetMouseButton(0)) {
if (!EventSystem.current.IsPointerOverGameObject()){
Target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
}
点击时仍向 UI 移动的 Android 触摸:
if (Input.touchCount > 0){
foreach (Touch touch in Input.touches){
int id = touch.fingerId;
if (!EventSystem.current.IsPointerOverGameObject(id))
{
Target = Camera.main.ScreenToWorldPoint(touch.position);
}
}
}
有任何想法吗?
解决方案
推荐阅读
- javascript - 我可以在没有 npm 或 node.js 的情况下使用 .dotenv 库作为 HTML 脚本导入吗?
- ios - 防止 SwiftUI 动画覆盖嵌套的 withAnimation 块
- python - 如何根据数据框的行值作为子字符串/包含在另一个数据框的行值中来连接两个数据框?
- python - 删除所有子域并仅获取根域 pyspark
- python-3.x - Python Card & Deck OOP
- php - 在 api 调用的结果中匹配 Urls
- javascript - 裁剪图像 url 作为道具 React
- docker - 卷不适用于 Datapower 和 docker
- computational-geometry - 在 OpenMesh 中哪里存储 VertexHandle 的 id?
- c++ - 8 各种棋子的皇后象棋问题