在要hit test的gameobject內加入Box Collider 2D
// Update is called once per frame
void Update() {
if (Input.GetMouseButtonDown(0))
{
print("mousedown");
RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
if (hit.collider != null)
{
print(hit.collider.gameObject.name);
}
}
}


Comment feed