public void TakePickUp(GameObject _pickUpObject) { PickUpBehaviourScript _pickUp = _pickUpObject.GetComponent <PickUpBehaviourScript>(); if (_pickUp.thisPickUpType == PickUpBehaviourScript.PickUpTypes.Credit) { GameControllerScript.currendCredits += _pickUp.CreditValue;//CreditValues[IndexOfCreditValue]; AudioControllerScript.activeInstance.PlaySound("CreditPickUp", Random.Range(0.8f, 1.2f)); } else if (_pickUp.thisPickUpType == PickUpBehaviourScript.PickUpTypes.HealthUp) { ChangeHealthBy(MaxHealth * 0.4f); currendHealth += MaxHealth * 0.4f; GameObject Go = Instantiate(_pickUp.VisualEffect, ShipGFX.transform); Destroy(Go, 3f); AudioControllerScript.activeInstance.PlaySound("HealthUp"); } else { StartCoroutine(ActivatePowerUpforTime(_pickUpObject)); } if (GameControllerScript.showTutorials == true && _pickUp.tutorialText != "") { InGameUIControllerScript.activeInstance.OpenTutorialText(_pickUp.tutorialText); } }
IEnumerator ActivatePowerUpforTime(GameObject _powerUpGo) { PickUpBehaviourScript _powerUp = _powerUpGo.GetComponent <PickUpBehaviourScript>(); bool createEffect = true; switch (_powerUp.thisPickUpType) { case (PickUpBehaviourScript.PickUpTypes.FireRateUp): fireRateMultiplyer = 0.6f; AudioControllerScript.activeInstance.PlaySound("FireRatePowerUp"); break; case (PickUpBehaviourScript.PickUpTypes.DamageUp): ProjectileBehaviourScript.damageMultiplyer = 1.2f; AudioControllerScript.activeInstance.PlaySound("DamagePowerUp"); break; case (PickUpBehaviourScript.PickUpTypes.Invincibility): EnemyBehaviourScript.noCollisionDamage = true; AudioControllerScript.activeInstance.PlaySound("InvincibilityPowerUp"); break; case (PickUpBehaviourScript.PickUpTypes.SloMo): Time.timeScale = 0.8f; AudioControllerScript.activeInstance.PlaySound("SloMoPowerUp"); break; case (PickUpBehaviourScript.PickUpTypes.Regeneration): regenerates = true; regenerationVisualEffectGo = Instantiate(_powerUp.VisualEffect, ShipGFX.transform); createEffect = false; AudioControllerScript.activeInstance.PlaySound("RegenerationPowerUp"); break; default: Debug.LogError("The PickUp -" + _powerUp.thisPickUpType + "- has no effect assinged!"); createEffect = false; break; } GameObject tempVisualEffectGo = null; if (createEffect == true && _powerUp.VisualEffect != null) { tempVisualEffectGo = Instantiate(_powerUp.VisualEffect, ShipGFX.transform); } yield return(new WaitForSeconds(_powerUp.duration)); createEffect = true; switch (_powerUp.thisPickUpType) { case (PickUpBehaviourScript.PickUpTypes.FireRateUp): fireRateMultiplyer = 1f; break; case (PickUpBehaviourScript.PickUpTypes.DamageUp): ProjectileBehaviourScript.damageMultiplyer = 1f; AudioControllerScript.activeInstance.StopSound("DamagePowerUp"); break; case (PickUpBehaviourScript.PickUpTypes.Invincibility): EnemyBehaviourScript.noCollisionDamage = false; AudioControllerScript.activeInstance.StopSound("InvincibilityPowerUp"); break; case (PickUpBehaviourScript.PickUpTypes.SloMo): Time.timeScale = 1f; break; case (PickUpBehaviourScript.PickUpTypes.Regeneration): regenerates = false; if (regenerationVisualEffectGo != null) { Destroy(regenerationVisualEffectGo); } createEffect = false; AudioControllerScript.activeInstance.StopSound("RegenerationPowerUp"); break; default: Debug.LogError("The PickUp -" + _powerUp.thisPickUpType + "- has no effect assinged!"); createEffect = false; break; } if (createEffect == true && _powerUp.VisualEffect != null) { Destroy(tempVisualEffectGo); } }