Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        if ((int)state == (int)gameState.battlePhase)
        {
            //continue spawning current wave
            sm.UpdateSpawn();

            //execute turret AI
            foreach (GameObject currentTurret in GameObject.FindGameObjectsWithTag("Turret"))
            {
                turret t = (turret)currentTurret.GetComponent("turret");
                t.Fire(new Vector2(9, 9));
            }

            //execute creep AI
            GameObject[] creeps = GameObject.FindGameObjectsWithTag("Creep");
            foreach (GameObject currentCreep in creeps)
            {
                creep c = (creep)currentCreep.GetComponent("creep");
                c.Seek(new Vector2(9, 9), currentPath, 10);
                c.updateStatuses();
            }

            //update missiles
            foreach (GameObject currentMissile in GameObject.FindGameObjectsWithTag("Missile"))
            {
                missile m = (missile)currentMissile.GetComponent("missile");
                m.Fly();
            }

            //check if wave is defeated
            if (creeps == null || creeps.Length == 0)
            {
                Debug.Log("here");
                if (sm.isWaveDefeated())
                {
                    updateAvailableUnits(sm.currentWave);
                    if (sm.currentWave == sm.totalWaves)
                    {
                        totalWin();
                    }
                    else
                    {
                        win();
                    }
                }
            }
            if (tm.selected == selectedState.creep && tm.selectedObject != null)
            {
                //apply stun
                creep c = (creep)tm.selectedObject.GetComponent("creep");
                c.applyStatus(creepStatus.stun, 3 * c.durationMultipliers[1]);
                //tm.selected = selectedState.none;
            }
            tm.selected  = selectedState.none;
            tm.clickable = true;
        }
    }