I am currently building a game where I need to generate some wires (as Bézier curves) using LineRenderer. After changing the width of each line
lineRenderer.SetWidth (0.15f, 0.15f);
I am attaching an EdgeCollider2D to the same game object (specifying the same points used in generating the Bézier curve). This seems to work. However, I would like to be able to know if the Mouse Pointer is at any time over the EdgeCollider2D (something similar to the popular Fruit Ninja game). I'm using Raycast as follows:
void CastRay() {
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast (ray.origin, ray.direction, Mathf.Infinity);
if (hit) {
Debug.Log (hit.collider.gameObject.name);
}
}
I'm calling the CastRay method inside the Update method. Because EdgeCollider2D does not have width (as expected), the log message is never produced.
Do I need to use a different type of Collider? Do I need to call CastRay somewhere else?