public List <VillagerStats> getAllVillagerStatsInBounds(Vector3 firstCorner, Vector3 secondCorner)
    {
        List <GameObject>    villagers = getAllVillagerObjects();
        List <VillagerStats> stats     = new List <VillagerStats>();
        float topLine;
        float botLine;
        float leftLine;
        float rightLine;

        if (firstCorner.y < secondCorner.y)
        {
            topLine = secondCorner.y;
            botLine = firstCorner.y;
        }
        else
        {
            topLine = firstCorner.y;
            botLine = secondCorner.y;
        }

        if (firstCorner.x < secondCorner.x)
        {
            leftLine  = firstCorner.x;
            rightLine = secondCorner.x;
        }
        else
        {
            leftLine  = secondCorner.x;
            rightLine = firstCorner.x;
        }

        for (int i = 0; i < villagers.Count; i++)
        {
            Vector3 position = villagers[i].transform.position;
            if (position.x >= leftLine && position.x <= rightLine && position.y <= topLine && position.y >= botLine)
            {
                VillagerGather gather = villagers[i].GetComponent <VillagerGather>();
                if (!gather.isWorkerBusy())
                {
                    stats.Add(villagers[i].GetComponent <VillagerStats>());
                }
            }
        }

        return(stats);
    }
    private void OnMouseDown()
    {
        GameObject     person = selectionManager.getCharacterById(id);
        VillagerGather gather = person.GetComponent <VillagerGather>();

        if (!gather.isWorkerBusy())
        {
            if (!selected)
            {
                setSelected(true);
                selectionManager.selectVillagerById(id);
            }
            else
            {
                setSelected(false);
                selectionManager.unselectVillagerById(id);
            }
        }
    }
Exemplo n.º 3
0
    // Init

    private void Awake()
    {
        villagerStats = gameObject.GetComponent <VillagerStats>();
        gather        = gameObject.GetComponent <VillagerGather>();
    }
    // Init

    private void Awake()
    {
        animator     = gameObject.GetComponent <Animator>();
        stats        = gameObject.GetComponent <VillagerStats>();
        gatherScript = gameObject.GetComponent <VillagerGather>();
    }