Exemplo n.º 1
0
    //warn the nearest volunteer there is someone cutting down the trees
    public Volunteers WarnNearestVolunteer(EvilPeople evilPerson)
    {
        float      closestDist      = Mathf.Infinity;
        Volunteers nearestVolunteer = null;

        if (m_PlayerVolunteer != null)
        {
            if (m_PlayerVolunteer.CheckCanChase())
            {
                float newDist = Vector2.SqrMagnitude(evilPerson.transform.position - m_PlayerVolunteer.transform.position);
                nearestVolunteer = m_PlayerVolunteer;
            }
        }

        foreach (Volunteers volunteer in m_NPCObjectPooler.m_VolunteerList)
        {
            if (!volunteer.gameObject.activeSelf)
            {
                continue;
            }

            //make sure volunteer is available to start chasing
            if (!volunteer.CheckCanChase())
            {
                continue;
            }

            float newDist = Vector2.SqrMagnitude(evilPerson.transform.position - volunteer.transform.position);
            if (newDist < closestDist)
            {
                closestDist      = newDist;
                nearestVolunteer = volunteer;
            }
        }

        if (nearestVolunteer != null)
        {
            //pass the evil person to the nearest volunteer
            nearestVolunteer.ChaseEvilPerson(evilPerson);
        }

        return(nearestVolunteer);
    }