LOS script not working completely.

I made a LOS script that runs in Update(). It works perfectly, until I spawn more than one player. Only the last player will have a line of sight when I do that even though they all have the same script. Is there some restriction to Raycast that I’m not aware of? Should I be using a for Loop to run through all of them in order, instead of firing away at once?

function CheckLoS()
{	
	var enemies : GameObject[]; 
	enemies = GameObject.FindGameObjectsWithTag("Enemy"); 
	
    for (var i =0; i < enemies.length; i++)  
    {
           var hitInfo : RaycastHit;     
           var rayLos = Physics.Raycast(transform.position, (enemies[i].transform.position - transform.position).normalized, hitInfo, sightRangeMax);
           if(rayLos  hitInfo.transform.gameObject == enemies[i]) 
            {
                enemies[i].renderer.enabled = true;                   
            }
            else
            {
            	enemies[i].renderer.enabled = false;          		
            }
        }
}

Never mind. The IF statement that sets the renderer is the problem.

Using Find from Update is BAD form. Even the documentation says so.

you either need to cache the enemies, or put your LOS function into a timed Invoke call (InvokeRepeating), or make it event based.