private void Spawn()
    {
        FormationData chosenFormation = formations[Random.Range(0, formations.Count)];

        if (Random.Range(0, 100f) <= chosenFormation.chance)
        {
            Formation chosen = chosenFormation.formation;
            chosen.Build();
            int   size   = chosen.row0.Count;
            float offset = size / 2f * unitGap;
            float xo     = Random.Range(-boundSize + offset, boundSize - offset);
            for (int i = 0; i < Formation.maxRows; i++)
            {
                List <string> row = chosen.allRows[i];
                for (int j = 0; j < row.Count; j++)
                {
                    string target = row[j];
                    if (target != "0" && target != "")
                    {
                        float   x   = xo + j * unitGap - offset;
                        Vector3 pos = transform.position;
                        pos.x += x;
                        pos.y += i * rowGap;
                        objectPooler.SpawnFromPool(target, pos, transform.rotation);
                    }
                }
            }
            nextSpawnTime = Time.time + 1f / spawnRate;
        }
    }
 public void FormationBuilderThrowsIfFormationIsUnknown()
 {
     Assert.Throws <UnknownFormationTypeException>(() => Formation.Build("4-4-3"));
 }
        public void Formation442Has2Attackers()
        {
            var formation = Formation.Build("4-4-2");

            Assert.AreEqual(formation.Postitions.Count(x => x.Role == PlayerRole.Attacker), 2);
        }
        public void Formation442Has4Midfielders()
        {
            var formation = Formation.Build("4-4-2");

            Assert.AreEqual(formation.Postitions.Count(x => x.Role == PlayerRole.Midfielder), 4);
        }
        public void Formation442Has1Goalkeeper()
        {
            var formation = Formation.Build("4-4-2");

            Assert.AreEqual(formation.Postitions.Count(x => x.Role == PlayerRole.Goalkeeper), 1);
        }
        public void Formation442Has11Players()
        {
            var formation = Formation.Build("4-4-2");

            Assert.AreEqual(formation.Postitions.Count, 11);
        }