Collision only works for one object

Hello everyone I have yet another problem with raycasting. here is my script

var dis : int = 5;

var hit : RaycastHit;

function Update () {

for (var touch : Touch in Input.touches) {



	if (touch.phase == TouchPhase.Began) {

	

		// Construct a ray from the current touch coordinates

		var ray = Camera.main.ScreenPointToRay (touch.position);

		

		if (Physics.Raycast (ray, hit, dis))

		{

			if (hit.collider.gameObject.tag == "Cubie2"){

		

			Debug.Log("You find a CUBIE!");

			Destroy(GameObject.FindWithTag("Cubie2"));

			

		if  (Physics.Raycast (ray, hit, dis))

		{

			if (hit.collider.gameObject.tag == "Cubie")

			{

			Debug.Log("You find a CUBIE2!");

			Destroy(GameObject.FindWithTag("Cubie"));

			

		if  (Physics.Raycast (ray, hit, dis))

		{

			if (hit.collider.gameObject.tag == "Cubie3")

			{

			Debug.Log("You find a CUBIE3!");

			Destroy(GameObject.FindWithTag("Cubie3"));

			

		if  (Physics.Raycast (ray, hit, dis))

		{

			if (hit.collider.gameObject.tag == "Cubie4")

			{

			Debug.Log("You find a CUBIE4!");

			Destroy(GameObject.FindWithTag("Cubie4"));

			

		if (Physics.Raycast (ray, hit, dis))

		{

			if (hit.collider.gameObject.tag == "Cubie5")

			{

			Debug.Log("You find a CUBIE5!");

			Destroy(GameObject.FindWithTag("Cubie5"));

		}

	}

}

}

}

}

}

}

}

}

}

}

}

My problem is this only works for 1 tag, Can some one please help me and sorry for the format I tried my best to get in it here as close to how it should be.

Blockquote

The problem here is that all your if statements are inside each other! It only works for the first one, because all the others will never execute if the first one doesn’t, and by definition if the first one does, all the others never will! You should instead do something like this (which is much cleaner anyway)

var ray = Camera.main.ScreenPointToRay (touch.position);

if (Physics.Raycast (ray, hit, dis))
{
    switch(hit.collider.tag)
    {
        case "Cubie2":
             // Do Cubie2 stuff
        break;
        case "Cubie":
             // Do Cubie stuff
        break;
        case "Cubie3":
             // Do Cubie3 stuff
        break;
       // And so on

    // At the end-
       default:
            // this is what happens if none of the above is true.
    }
}

Switch statements take a single variable, and then compare it against a number of ‘cases’- if it is the same as the case label, then it executes the code under that label. If it matches none of them, it falls through to the ‘default’ case, and executes that.