Esempio n. 1
0
 public void ActivatePowerUp(bool isHealthPowerUp)
 {
     if (isHealthPowerUp)
     {
         _lives += 1;
         _healthBar.AddHeart();
     }
     else
     {
         PlayAudioSourceByGameObjectName("PowerUpPickUpSound");
         //randomize power up each time when collecting
         System.Random rand = new System.Random();
         _powerUpsIndex = rand.Next(0, _powerUps.Count);
         Debug.Log("Index: " + _powerUpsIndex);
         if (_powerUps[_powerUpsIndex].name.Contains("Shield"))
         {
             GameObject shield = Instantiate(_powerUps[_powerUpsIndex], this.transform.position, Quaternion.identity, this.transform);
             Destroy(shield.gameObject, _powerupTimeout);
         }
         else
         {
             _usePowerUp = true;
             StartCoroutine(DeactivatePowerUp());
         }
         _uiManager.InstantiatePowerUpBar(GetActivePowerUpType(_powerUps[_powerUpsIndex]), _powerupTimeout);
     }
 }