Trouble with Raycasting through a trigger

Hi Unity,

I am trying to pass a raycast through a trigger collider and hit a box collider on the other side. I have read a few posts on layers and what not and eventually settled on RaycastAll. Problem is, I must have done something wrong because my raycast isnt hitting at all, even when I remove the trigger collider all together. I seemed to have copied the example code exactly, can someone spot my mistake?

	RaycastHit[] hits;
	Ray ray;
	//Quick References
	public GameObject line;
void Update () 
			print ("mousedown");
			ray = Camera.main.ScreenPointToRay(Input.mousePosition);
			hits = Physics.RaycastAll(ray, Mathf.Infinity);
			int cnt = 1;
			while (cnt < hits.Length)
				print ("while loop");
				if(hits[cnt].transform.tag == "Room")
					print ("Success");
					Instantiate(line, new Vector3(Input.mousePosition.x, Input.mousePosition.y, hits[cnt].point.z + 3), Quaternion.identity);

Whats strange is the “While Loop” print never even shows. I dont use while loops often, normally for loops, so maybe my syntax is wrong? I just used it because thats what the unity doc had.

The hits array is zero based, so if you do set cnt to 1, it will only print something out if the RaycastAll hits two or more items. Change it to:

int cnt = 0;