public void Die() { // Don't accidentally spawn multiple pickups if (!dead) { dead = true; // Play death sound SFXHandler.PlaySound("enemydeath"); // Spawn pickups while (scoreValue > 0 && powerValue > 0) { if (scoreValue > 0) { StageHandler.SpawnPickup(0, transform.position, (Vector2)transform.position + (Random.insideUnitCircle + Vector2.up) * .5f, .2f); scoreValue--; } if (powerValue > 0) { StageHandler.SpawnPickup(1, transform.position, (Vector2)transform.position + (Random.insideUnitCircle + Vector2.up) * .5f, .2f); powerValue--; } } // Destroy object Destroy(gameObject); } }
private void DropPower(Vector3 startPos, float amount) { // Calculate number of big and small pickups needed // Large pickup = .12 power, small pickup = .03 power // TODO: Get pickup values in Start()? int bigPickup = Mathf.FloorToInt(amount / .12f); int smallPickup = Mathf.FloorToInt((amount - .12f * bigPickup) / .03f); // Spawn pickups above player while (smallPickup > 0 && bigPickup > 0) { if (smallPickup > 0) { StageHandler.SpawnPickup(1, startPos, Random.insideUnitCircle + StageHandler.center + 1.5f * Vector2.up, .2f); smallPickup--; } if (bigPickup > 0) { StageHandler.SpawnPickup(3, startPos, Random.insideUnitCircle + StageHandler.center + 1.5f * Vector2.up, .2f); bigPickup--; } } }
// Turn all bullets to score pickups (for bombs, spell cards, etc.) public static void BulletsToScore() { GameObject[] bullets = new GameObject[instance.transform.childCount]; int i = 0; foreach (Transform bullet in instance.transform) { if (bullet.CompareTag("Enemy")) { bullets[i] = bullet.gameObject; i++; StageHandler.SpawnPickup(4, bullet.position); } } // Can't destroy bullets while looping through them foreach (GameObject bullet in bullets) { Destroy(bullet); } }