// Update is called once per frame
 void Update()
 {
     if (keepSpawning && nav.enabled && Time.time >= timeOfLastSpawn + timeBetweenSpawns)
     {
         float chanceForExtraBody = spawnChance / numBodiesSpawned;
         float randNum            = Random.Range(0f, 1f);
         if (chanceForExtraBody > randNum)
         {
             timeOfLastSpawn = Time.time;
             UnitAnimated body = (UnitAnimated)uGen.MakeUnit(true, 7, spawn, this.noise);
             bodyAndTail.Add(body);
             body.SetTimePerTexture(9999f);
             body.SetSpeedAndAccel(this.speed, this.acceleration);
             body.SetArmor(900f);
             numBodiesSpawned++;
         }
         else
         {
             UnitAnimated tail = (UnitAnimated)uGen.MakeUnit(true, 8, spawn, this.noise);
             bodyAndTail.Add(tail);
             tail.SetTimePerTexture(9999f);
             tail.SetSpeedAndAccel(this.speed, this.acceleration);
             tail.SetArmor(1400f);
             keepSpawning = false;
         }
     }
 }    //Update()
Beispiel #2
0
    public void train()
    {
        if (castle.canPurchase(getPrice()))
        {
            // Start training!
            NeuralNode node = NeuralNode.create(neuralNodeType);
            cFire.node = node;
            float noise = getNoise();

            for (int i = 1; i <= TOTAL_ENEMY_UNITS; i++)
            {
                for (int j = 0; j < getQuantityOfEnemy(i); j++)
                {
                    Unit unit = uGen.MakeUnit(true, ENEMY_INDICES[i - 1], farOff, noise, true);
                    if (unit is UnitAnimated)
                    {
                        UnitAnimated ua     = (UnitAnimated)unit;
                        Texture2D[]  texes  = ua.textures;
                        int          texIdx = j % texes.Length;
                        ua.setTexture(texes[texIdx]);
                    }

                    node.AddToTrainingSet(unit, isEnemyTarget(i));
                    unit.DestroyMe();
                }
            }

            for (int i = 1; i <= TOTAL_ALLY_UNITS; i++)
            {
                for (int j = 0; j < getQuantityOfAlly(i); j++)
                {
                    Unit unit = uGen.MakeUnit(false, ALLY_INDICES[i - 1], farOff, noise, true);
                    if (unit is UnitAnimated)
                    {
                        UnitAnimated ua     = (UnitAnimated)unit;
                        Texture2D[]  texes  = ua.textures;
                        int          texIdx = j % texes.Length;
                        ua.setTexture(texes[texIdx]);
                    }

                    node.AddToTrainingSet(unit, isAllyTarget(i));
                    unit.DestroyMe();
                }
            }

            node.LearnUnits();
            castle.makePurchase(getPrice());
            Time.timeScale = previousTimeScale;

            // Close window
            GetComponent <Canvas> ().enabled = false;
            Camera.main.GetComponent <BuildingPlacement> ().placeableBuildingOld.SetSelected(true);
        }
    }