First of all, I think this is not very hard to answer.
I have made a script that I put to my enemy object and it makes my enemy go towards the closest player of my team.
The bad thing about this script is that I must have 5 players in each team and it’s very boring when I have to link all me enemyes to all my players and all my players to all my enemyes.
Can I make a script that it calculates which enemy is the closect (all enemies have the same tag) no matter how many of them are there in the game.
I can calculate the distance like this:
var enemy:Transform;
var distance_enemy:float = Vector3.Distance(enemy.position, transform.position );
I can calculate the minimum value like this:
//This is in my script (only 5 players)
var smallest:float = Mathf.Min(distance_enemy1, distance_enemy2, distance_enemy3, distance_enemy4, distance_enemy5);
I guess I could put all objects into an array and find the closest one but I don’t know how to do that.
I would really need this becouse I’m stuck with only 5 players and it’s kind of boring like that.