Question by
DannyvdM · Jul 07, 2016 at 02:03 PM ·
gameobjectraycastmesh2d-physics
Raycast doesn't find mesh
I have an automated layout generator, made from hexagon meshes. I want to be able to click on it.
I want to do this with a raycast, but unfortunately, the raycast can't find any colliders. The different meshes have a mesh collider.
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Debug.Log("Click!");
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);
if(hit.collider != null)
{
Debug.Log("Yeah");
}
}
}
There are lot's of questions and answers about this topic , but none of these actually helped. I couldn't find a question specific for meshes.
Comment