What is wrong with my code?

I have a lot of cubes and I select them with this script:

#pragma strict
function Update()
{
    var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    var hit : RaycastHit;
 
    if(Input.GetMouseButtonDown(0))
    {
        if(Physics.Raycast(ray,hit,1000))
       { 
           if (hit.transform.tag == "cube")
           {
             hit.transform.tag="Untagged";
             hit.transform.renderer.material.color=Color.red;
             var cubes: GameObject[];
             cubes = GameObject.FindGameObjectsWithTag ("cube");
             for (var cube : GameObject in cubes) 
          {
                 cube.renderer.material.color=Color.black;
          }
          hit.transform.tag="cube";
                 Debug.Log("Cube is "+hit.transform.name);
 
                 
}
}
}
}

The problem is only right half of them are being selected. Here is a screenshot I took. Sorry for bad explanatation.

[20837-screenshot+(30).png|20837]

Thanks in advanced.

Problem is you deselect the cube you just clicked again…

hit.transform.tag="cube";