Ejemplo n.º 1
0
    void BeginMerge()
    {
        //get everything in the lane
        List <Enemy> zoneGuys = Dial.GetAllEnemiesInZone(SpawnIndexToZoneID(mergeIdx));

        if (zoneGuys.Count < 2)
        {
            //abort merge and move on
            Debug.Log("not enough enemies, merge aborted");
            PickTargetZone();
            hitYet       = false;
            currentState = state.DECIDING;
            return;
        }
        //create facsimilies
        facsimiles.Clear();
        Vector2 centerTotals = new Vector2(0f, 0f);
        float   progTotals   = 0f;

        foreach (Enemy e in zoneGuys)
        {
            GameObject facs = GameObject.Instantiate(e.gameObject);
            GameObject.Destroy(facs.GetComponent <Enemy>());
            facs.tag = "Untagged";
            MegaboidFacsimile mf = facs.AddComponent <MegaboidFacsimile>() as MegaboidFacsimile;
            facs.transform.SetParent(Dial.spawnLayer, false);
            facsimiles.Add(facs);
            //get their centers
            centerTotals += e.gameObject.GetComponent <RectTransform>().anchoredPosition;
            progTotals   += e.GetProgress();
        }
        center     = new Vector2(centerTotals.x / zoneGuys.Count, centerTotals.y / zoneGuys.Count);
        progcenter = progTotals / zoneGuys.Count;
        foreach (GameObject mfg in facsimiles)
        {
            mfg.GetComponent <MegaboidFacsimile>().InitializeMovement(center, mergeTimer);
        }

        //old guys: kill 'em all
        foreach (Enemy e in zoneGuys)
        {
            Dial.CallEnemyAddBonus(e);
        }
        foreach (Enemy e in zoneGuys)
        {
            Destroy(e.gameObject);
        }

        currentState = state.MERGING;
        mergeTimer.Restart();
    }