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;
}
}
}