1 第一种Physics2D.Raycast
RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
if(hit.collider != null)
{
Debug.Log ("Target Position: " + hit.collider.gameObject.transform.position);
}
2 第二种Physics2D.OverlapPointAll
Collider2D[] col = Physics2D.OverlapPointAll(Camera.main.ScreenToWorldPoint(Input.mousePosition));
if(col.Length > 0)
{
foreach(Collider2D c in col)
{
//do what you want
}
}
当然可以
Collider2D col=Physics2D.OverlapPoint(Camera.main.ScreenToWorldPoint(Input.mousePosition);