please use code tags to make your code easier to read, also the line of the error would be nice, because you have multiple lists.
Just a guessing, because it´s hard to say anything without the error message: You clear your targets list in “DeselectTarget()”, do you try afterwards to get index[0] from it in “SelectTarget()” on any script ?
well it only happens on start… basicly the script works like this all enemies and allies assign themselve to a list on the GameController. They fetch their opponent list addAllEnemies… and selects the closest one in that list. I think the DeselectTarget(), is the cause… but I did if (selectedTarget != null)… so…
I also write my scripts in such a way that I dont get anything from other scripts the scripts assign their own variable… hence:
selectedTarget = targets[0];
core.logic.aiTarget = selectedTarget.transform;
`so can I not say something like if (!targets.empty){
selectedTarget = targets[0];
}
you get that? also: I think this might work. I dont know how to implement it