public void SpawnBallsByHp(int totalHP, float percentage) { int hpLeft = (int)(totalHP * percentage); int ballCount = 4; LevelProperties.balls[] balls = new LevelProperties.balls[ballCount]; for (int i = 0; i < ballCount; i++) { int hp = 0; int split = 0; if (i == ballCount - 1) { hp = (int)(hpLeft * Random.Range(0.5f, 0.9f)); hp += hp % 2 == 0 ? 0 : 1; hpLeft -= hp; split = hpLeft / 2; } else { hp = (int)(hpLeft * Random.Range(0.05f, 0.3f) * (Calc.map(i, 0, ballCount - 1, 1, 2) * percentage)); hp += hp % 2 == 0 ? 0 : 1; split = (int)(hp * Random.Range(0.2f, 0.8f)); hpLeft -= (hp + split); } balls[i] = new LevelProperties.balls(hp, new int[] { split, split }, 4 * i); } StartCoroutine(SpawnRoutine(balls)); }
// TODO : merge 2 funcs public void Spawn(LevelProperties.balls ballProperties) { Ball ballClone = MonoBehaviour.Instantiate(ballPrefab); ballClone.transform.parent = ballParent; ballClone.SetProperties(1.0f, Vector3.up * GameManager.instance.gameProperties.gravity, ballProperties.hp, ballProperties.splits); ballClone.IgniteFrom(spawnLocations.GetChild(Random.Range(0, spawnLocations.childCount))); }