为什么此代码在触摸后不会打印任何内容?
void Update()
{
if (Input.touchCount > 0)
{
RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position), Vector2.zero);
if (hit)
{
print(hit.transform.name);
}
}
}
答案 0 :(得分:-1)
试试这个:
if (Input.touchCount > 0)
{
RaycastHit2D hit;
if (Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position), Vector2.zero, out hit))
{
print(hit.transform.name);
}
}