private void NextLevel() { // Update level ++level; uncompleted_platforms = 0; ref_text_level.text = "Level " + level.ToString(); // Destroy all cubes foreach (GameObject go in GameObject.FindGameObjectsWithTag("Digit")) { Destroy(go.gameObject); } // Difficulty adjustment int operations_used_max = ((level - 1) / difficulty_raise_operations) + 1; int operations_used = Random.Range(1, operations_used_max); int platforms_used = ((level - 1) / difficulty_raise_platforms) + 1; platforms_used = (platforms_used <= script_platforms.Length) ? platforms_used : script_platforms.Length; int max_inc = (level - 1) / difficulty_raise_max; // Update platforms and calculate cubes List <Behavior_Digit.Operator> digit_ops = new List <Behavior_Digit.Operator>(); List <int> digit_values = new List <int>(); for (int i = 0; i < script_platforms.Length; ++i) { if (i < platforms_used) // Platform in use { // Generate valid equation int total = Random.Range(random_val_min, random_val_max + max_inc); digit_values.Add(total); for (int j = 0; j < operations_used; ++j) { int value = Random.Range(random_val_min, random_val_max + max_inc); digit_values.Add(value); Behavior_Digit.Operator op = RandomOperator(); digit_ops.Add(op); total = Behavior_Digit.ApplyOperation(op, total, value); } script_platforms[i].Reset(total, true); ++uncompleted_platforms; } else // Platform not in use { script_platforms[i].Reset(0, false); } } // Spawn cubes, so they spawn all at once foreach (Behavior_Digit.Operator op in digit_ops) { script_spawner.SpawnOp(op); } foreach (int value in digit_values) { script_spawner.SpawnValue(value); } // Update variables start_time = Time.time; }
public void SpawnOp(Behavior_Digit.Operator o) { GameObject digit = Spawn(); digit.GetComponent <Behavior_Digit>().Initialize(o); }