- Home /
 
 
               Question by 
               BZS · Jan 19, 2014 at 02:19 AM · 
                javascriptgridcubeselection  
              
 
              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.

Thanks in advanced.
 
                 
                screenshot (30).png 
                (6.4 kB) 
               
 
              
               Comment
              
 
               
              I know what's wrong with your title... Please change it.
Elaborate on 'the right half' since a primitve cube has no halves per se (the screenshot tells me nada);
Answer by HappyMoo · Jan 19, 2014 at 02:29 AM
Problem is you deselect the cube you just clicked again...
 hit.transform.tag="cube";
 
              Your answer
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Primitive Cube Texturing Help 3 Answers
RTS Grid Idea? 1 Answer
[Android]How to move an object and have it snap to grid? 1 Answer
How to make a selection system? 1 Answer