public void SpawnShooters(int capacity) { if (capacity == 0) { Debug.Log("No Risk"); return; } while (capacity > 0) { ShooterRisk sr = PickShooter(capacity); if (sr.risk == -1) { // No valid choices return; } BulletRisk br = PickBullet(capacity); if (br.risk == -1) { // No valid choices return; } float xpos = Random.Range(minPos, maxPos); float ypos = Random.Range(minPos, maxPos); Vector3 screenPosition = Camera.main.ViewportToWorldPoint(new Vector3(xpos, ypos, 0)); GameObject g = Instantiate(sr.prefab, new Vector3(screenPosition.x, screenPosition.y, 0), Quaternion.identity); StaticShooter ss = g.GetComponent <StaticShooter>(); List <Vector3> playerColours = GameStores.GetPlayerColours(); Vector3 col = playerColours[Random.Range(0, playerColours.Count)]; ss.setColour(col); ss.missile = br.prefab; ss.dropOnDeath = drops; ss.dropChance = dropChance; capacity -= Mathf.Max(sr.risk, br.risk); } }
private BulletRisk PickBullet(int capacity) { List <BulletRisk> bs = BulletList(); while (bs.Count > 0) { int choice = Random.Range(0, bs.Count); if (bs[choice].risk <= capacity) { return(bs[choice]); } else { bs.RemoveAt(choice); } } BulletRisk debug = new BulletRisk { risk = -1 }; return(debug); }