script optimization (choosing an object in game by click)

Hi everyone, i have little question. My script works fine but i dont really sure that this method is good.

function Update () {
   gameControl.worldpos = camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x,Input.mousePosition.y,0));
      if (Input.GetMouseButtonUp(0)&&gameControl.worldpos.y<-0.5){
       for (var i:int=0;i<fastCellArray.length;i++){
         if (gameControl.worldpos.x>fastCellArray<em>.GetComponent.<cellScript>().selfTransform.position.x-0.5&&gameControl.worldpos.x<fastCellArray<em>.GetComponent.<cellScript>().selfTransform.position.x+0.5&&gameControl.worldpos.y>fastCellArray_.GetComponent.<cellScript>().selfTransform.position.y-0.5&&gameControl.worldpos.y<fastCellArray*.GetComponent.<cellScript>().selfTransform.position.y+0.5){*_</em></em>
 <em><em><em>_fastCellArray*.GetComponent.<cellScript>().clicked=true;*_</em></em></em>
 <em><em><em>_*}*_</em></em></em>
 <em><em><em>_*}*_</em></em></em>
 <em><em><em>_*}*_</em></em></em>
<em><em><em>_*}*_</em></em></em>
<em><em><em>_*```*_</em></em></em>
<em><em><em>_*<p>Its choosing an object from array and make some actions with that object. Is it better than making click-test in each cell Object? (I've got permanent amount of cell Objects, that wont be changed, 27 objects)</p>*_</em></em></em>

Well, for future reference I'd replace

Vector3(Input.mousePosition.x,Input.mousePosition.y,0)

by Input.mousePosition. I also notice you're missing at least one "&" in your if() statement. The very first AND consists of only one "&" in stead of two.

Other then that and the extremely confusing if() statement it looks fine. I always prefer to have a single function iterate through it and see if you clicked it rather then adding a "click-test" on each Object. Although I guess it might be slightly faster, but for 27 objects I wouldn't worry.


What I meant with it 'looking confusing' is that you don't indent consistently, never use space and keep to much on a single line when you don't need to. To me, personally, it would look a lot clearer like this:

function Update () {    

    gameControl.worldpos = camera.main.ScreenToWorldPoint(Input.mousePosition);   

    if (Input.GetMouseButtonUp(0)&&gameControl.worldpos.y<-0.5){      

        for (var i:int=0;i<fastCellArray.length;i++){

            if  (   gameControl.worldpos.x > fastCellArray*.GetComponent.<cellScript>().selfTransform.position.x - 0.5* 
 _&&  gameControl.worldpos.x < fastCellArray*.GetComponent.<cellScript>().selfTransform.position.x + 0.5*_ 
 <em>_&&  gameControl.worldpos.y > fastCellArray*.GetComponent.<cellScript>().selfTransform.position.y - 0.5*_</em> 
 <em><em>_&&  gameControl.worldpos.y < fastCellArray*.GetComponent.<cellScript>().selfTransform.position.y + 0.5 )*_</em></em> 
 <em><em>_*{*_</em></em>
 <em><em><em>_fastCellArray*.GetComponent.<cellScript>().clicked=true;*_</em></em></em>
 <em><em><em>_*}*_</em></em></em> 
 <em><em><em>_*}*_</em></em></em> 
 <em><em><em>_*}*_</em></em></em> 
<em><em><em>_*}*_</em></em></em>
<em><em><em>_*```*_</em></em></em>