Look at issues

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

The correct way to do this is to have a different tag for your targets. The reason that you tag objects is to tell them apart; when you tag them all the same, you’ll treat them all the same. Make your player “Player1” and give the targets another tag; adjust your script accordingly.