Пример #1
0
    public Transform FindEnemy()
    {
        Transform nearest              = null;
        float     nearestDistance      = float.PositiveInfinity;
        List <CharacterBehaviour> team = board.GetTeam(TeamNumber == 1 ? 0 : 1);

        foreach (CharacterBehaviour enm in team)
        {
            Vector3 enemyPosition = enm.transform.localPosition;
            Vector3 myPosition    = this.transform.localPosition;
            float   distance      = Vector3.Distance(myPosition, enemyPosition);
            if (enm.Lifebar > 0 && (nearest == null || distance < nearestDistance))
            {
                nearest         = enm.transform;
                nearestDistance = distance;
            }
        }
        return(nearest);
    }