Hi, I’m having problems detecting a raycast with a BoxCollider2D. The object isn’t marked as a Trigger, I’m using this code:
void Update ()
{
// Use Raycast to pick cards that have mesh colliders attached...
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
Debug.DrawLine (ray.origin, hit.point);
if (Input.GetMouseButtonDown (0)) {
if (Physics.Raycast (ray, out hit, 500f)) {
Debug.Log ("Hit: " + hit.collider.gameObject.name);
if (hit.collider.tag == "Pig") {
animator = hit.collider.GetComponent<Animator> ();
if (!animator)
Debug.Break ();
animator.SetBool ("Flip", true);
}
} else {
Debug.Log ("Nothing there");
}
}
}
It never seems to return a collision (outputs ‘Nothing there’ in code below). The tags are setup up correctly, the object has a boxCollider2D.
Is there something specific I’m not address for boxCollider2D?
Thanks for any help!