Hello guys! I use this script below for automatic aiming at the nearest target. It works briliant, but i have one issue, - my character also must have tag “Player1”, and of course if i set it - he begins to aim into itself. How can i make, that my character aim to all other target with tag “Player1”, excluding himself? Or maybe exist better way get similar effect?
function Update() {
var waypoints: GameObject[] = GameObject.FindGameObjectsWithTag("Player1");
var closest: GameObject;
var closestDist = Mathf.Infinity;
for (waypoint in waypoints) {
var dist = (transform.position - waypoint.transform.position).sqrMagnitude;
if (dist < closestDist) {
closestDist = dist;
closest = waypoint;
}
}
transform.LookAt(closest.transform);