unity3d - 计算点击次数
问题描述
我想使用 Unity 计算页面上的点击次数以及每隔几秒出现的硬币的点击次数。你能告诉我如何获得页面上的点击次数吗?
每次我想分别计算硬币和页面的点击次数。
解决方案
它不清楚你的想法coin
。它是一个 UI 元素或一个GameObejct
.
我想它是一个带有RigidBody
and的对象Collider
:
public class HitDetector : MonoBehaviour
{
public static int allCounter = 0;
public static int hitCounter = 0;
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
allCounter++;
if (IsHit())
{
hitCounter++;
}
Debug.Log($"All: {allCounter} & hit: {hitCounter}");
}
}
private bool IsHit()
{
return Physics2D.Raycast(Camera.current.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
}
}
推荐阅读
- sql - “select * from where 'datetime' >= NOW() - INTERVAL 6 MONTH”的性能
- android - 将文件保存到 Android Studio 的内部目录
- c# - 启用 CORS 后访问限制不起作用
- javascript - Uml / sequence / package / ... JavaScript 和 Electron 应用程序的图表替代方案?
- mysql - Oracle SQL 查询的问题
- django - Chart.js 和 Django 供多个用户使用
- javascript - 为什么我的 JQuery/CSS 代码在我将它导入到我的 Wordpress 网站时不起作用?
- mysql - Sqoop mysql错误-通信链路故障
- google-chrome - 不安全的内容被阻止
- docker - 如何在 Docker 上运行的 thingboard 中连接 cassandra