我想使用Unity来计算页面上的点击量,以及每隔几秒钟出现的硬币的点击量。你能告诉我怎样才能得到页面的点击量吗?
每次我都希望硬币和页面上的点击量分别计算出来。
发布于 2021-04-12 02:20:22
现在还不清楚你对coin有什么想法。它是一个UI元素或GameObejct。
我认为它是一个带有RigidBody和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);
}
}https://stackoverflow.com/questions/67048031
复制相似问题