Пример #1
0
    private script_boidGroup FindClosestGroup()
    {
        script_Manager.Team allies = manager.GetTeam(team);

        float shortestDistance = 500.0f;
        int   shortestIndex    = -1;

        for (int i = 0; i < allies.GetSize(); i++)
        {
            GameObject target = allies.GetObject(i);

            if (target.GetComponent <script_boidGroup>())
            {
                float distance = Vector3.Distance(transform.position, target.transform.position);
                if (distance != 0 && distance < shortestDistance)
                {
                    shortestDistance = distance;
                    shortestIndex    = i;
                }
            }
        }

        if (shortestIndex != -1)
        {
            return(allies.GetObject(shortestIndex).GetComponent <script_boidGroup>());
        }
        return(null);
    }
Пример #2
0
    private GameObject CalculateTarget()
    {
        script_Manager.Team opponent = manager.GetOpponent(team);
        float maxRadius        = 10.0f;
        float shortestDistance = maxRadius;
        int   shortestIndex    = -1;

        for (int i = 0; i < opponent.GetSize(); i++)
        {
            GameObject target = opponent.GetObject(i);

            if (target)
            {
                float distance = Vector3.Distance(transform.position, target.transform.position);

                if (distance < maxRadius && distance < shortestDistance)
                {
                    shortestDistance = distance;
                    shortestIndex    = i;
                }
            }
        }

        if (shortestIndex != -1)
        {
            return(opponent.GetObject(shortestIndex));
        }
        return(null);
    }