i have come across a problem with unity RayCastHit2D and it wont hit a spawned object regardless of what i do. i even did a DrawRay and i can see it goes right through the spawned object and does not register a Hit on the object? even if the object has a 2d collider.
also my Spawned Objects are Sprites.
if (Input.GetMouseButtonDown(0))
{
Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast(mousePos,Vector2.zero);
if (hit.collider != null)
{
Debug.Log(hit.collider.name);
}
}
}