Esempio n. 1
0
    private RecruitmentAreaUnit SpawnUnit()
    {
        GameObject unitGameObject = Instantiate(unitPrefab) as GameObject;

        unitGameObject.transform.position = Vector3.zero;
        RecruitmentAreaUnit unit = unitGameObject.GetComponent <RecruitmentAreaUnit>();

        unit.transform.parent = transform;
        unit.SetColour(unitColor);
        unit.minX = -groundWidth / 2.0f;
        unit.maxX = groundWidth / 2.0f;

        float startingXPosition = 0.0f;

        RecruitmentAreaUnit.UnitDirection direction;
        if (Random.Range(0, 2) == 1)
        {
            startingXPosition += 0.1f;
            direction          = RecruitmentAreaUnit.UnitDirection.Right;
        }
        else
        {
            startingXPosition -= 0.1f;
            direction          = RecruitmentAreaUnit.UnitDirection.Left;
        }
        unit.direction = direction;

        unit.transform.position      = Vector3.zero;
        unit.transform.localPosition = new Vector3(startingXPosition, 0.0f, 0.0f);
        float scale = 1.2f;

        unit.transform.localScale = new Vector3(scale, scale, scale);
        units.Add(unit);
        return(unit);
    }
Esempio n. 2
0
    private void DespawnUnit()
    {
        int index = Random.Range(0, units.Count);
        RecruitmentAreaUnit unit = (RecruitmentAreaUnit)units[index];

        units.RemoveAt(index);
        Destroy(unit.gameObject);
    }
Esempio n. 3
0
    public int DestroyAllUnits()
    {
        int count = units.Count;

        for (int i = 0; i < count; i++)
        {
            RecruitmentAreaUnit unit = units[i] as RecruitmentAreaUnit;
            DestroyObject(unit.gameObject);
        }
        units.Clear();
        for (int i = 0; i < collectingState.Length; ++i)
        {
            collectingState[i].collecting = false;
        }
        return(count);
    }
Esempio n. 4
0
    public int DestroyAllUnitsOfColour(UnitColour colour)
    {
        int numRemoved = 0;

        for (int i = units.Count - 1; i >= 0; i--)
        {
            RecruitmentAreaUnit unit = units[i] as RecruitmentAreaUnit;
            if (unit.GetColour() == colour)
            {
                DestroyObject(unit.gameObject);
                units.RemoveAt(i);
                numRemoved++;
            }
        }
        collectingState[(int)colour].collecting = false;
        return(numRemoved);
    }
Esempio n. 5
0
    void UpdateCollecting()
    {
        int count = units.Count;

        for (int j = 0; j < count; j++)
        {
            RecruitmentAreaUnit unit = units[j] as RecruitmentAreaUnit;
            int i = (int)unit.GetColour();
            if (collectingState[i].collecting)
            {
                unit.WalkToGoal(collectingState[i].doorPosition, collectingState[i].timeRemaining);
            }
        }
        for (int i = 0; i < collectingState.Length; ++i)
        {
            collectingState[i].timeRemaining -= Time.deltaTime;
            if (collectingState[i].timeRemaining <= 0)
            {
                collectingState[i].collecting = false;
            }
        }
    }