我的手机游戏存在问题,我目前正在Unity中进行开发。 在我的脚本中,我通过RaycastHit2D检测到触摸,然后销毁了触摸的对象(在我的情况下是雨滴)。 唯一的问题是,当我运行游戏并触摸雨滴时,它并不总是有效。 仅当我在下面轻轻触摸时,它才有效。 我正在为雨滴预制件使用的Circle Collider 2D还好,所以我认为这不会造成麻烦。
我的脚本:
void Update()
{
GetInput();
}
private void GetInput()
{
foreach (Touch touch in Input.touches)
{
if (touch.phase == TouchPhase.Began)
{
Vector2 WorldPoint = Camera.main.ScreenToWorldPoint(touch.position);
RaycastHit2D hit = Physics2D.Raycast(WorldPoint, Vector2.zero);
GameObject collider = hit.collider.gameObject;
if (collider.tag == "Tropfen")
{
Destroy(collider);
}
}
}
}