private void spawnPickups() { int rng = Utils.Random(0, MAX_RNG); if (rng % 10 == 0) { PickupShield shield = new PickupShield(); AddChild(shield); shield.SetXY(this.x, Utils.Random(shield.height, game.height - MyGame.TILE_SIZE)); } else if (rng % 10 != 0 && rng % 5 == 0) { PickupHeart drugs = new PickupHeart(); AddChild(drugs); drugs.SetXY(this.x, Utils.Random(drugs.height, game.height - MyGame.TILE_SIZE)); } else { PickupCoin coin = new PickupCoin(); AddChild(coin); coin.SetXY(this.x, Utils.Random(game.height - MyGame.TILE_SIZE - 32, game.height - MyGame.TILE_SIZE - 32)); } }
void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Enemy")) { if (isInvincible == false) { PlayerDamage.PlayOneShot(PlayerDamage.clip); LoseHealth(); StartCoroutine(SetInvulnerability()); } } if (other.CompareTag("Heart")) { if (health < hearts.Length) { PickupHeart.PlayOneShot(PickupHeart.clip); health++; hearts[health - 1].sprite = FullHeart; Destroy(other.gameObject); } } if (other.CompareTag("Coin")) { if (PlayerPrefs.GetInt("CoinFirstUpgradeBool") == 0) { Score.CoinStorage += 1 * 1; } if (PlayerPrefs.GetInt("CoinFirstUpgradeBool") == 1) { Score.CoinStorage += 1 * (PlayerPrefs.GetInt("CoinMultiplier")); } PickupCoin.PlayOneShot(PickupCoin.clip); Destroy(other.gameObject); } }