PowerUp Timer
I have successfully created a slow motion power up and i thought this script would allow me to set the time scale at any speed I wanted, but if I set the timescale at 1.5 the timescale never returns back to 1. If I set the timescale to 0.5 it works fine. I also tried dividing the duration variable (in the slomoroutine) like so: duration=time/speed. Still nothing. What could be causing this? Help would appreciated.
Here's my code:
 using UnityEngine;
 using System.Collections;
 
 public class TimeChangingPowerUp : MonoBehaviour {
 
     public GameObject particle;
     public AudioClip powerUpSound;
     public float time;
     public float speed;
     //private bool Active=false;
     //private bool playerEntered;
 
     /*public void ActivatePowerUpSlowMotion(float time, float speed)
     {
         StartCoroutine (SlowMoRoutine (time, speed));
     }*/
 
     /*void Update(){
 
         if (Active) {
             
             Destroy (gameObject, 3);
 
         }
         
     }*/
 
     IEnumerator SlowMoRoutine(float time, float speed)
     {
         //Active = true;
         //time = Time.unscaledTime;
         //Destroy(gameObject );
     //float duration = time / speed;
         float duration = time * speed;
         Time.timeScale = speed;
         yield return new WaitForSeconds (duration);
         Time.timeScale = 1f;
         Destroy (gameObject);
 
     }
 
     void OnTriggerEnter2D(Collider2D other){
 
         if (other.tag == "Player") {
             
             //Active = true;
             GameObject clonedParticle;
             clonedParticle =Instantiate (particle, transform.position, transform.rotation) as GameObject ;
             GameObject sound = new GameObject ();
             sound.transform.position = transform.position;
             AudioSource audioSource = sound.AddComponent<AudioSource> ();
             audioSource.clip = powerUpSound;
             audioSource.Play ();
             Destroy (clonedParticle, 1.2f);
             Destroy (sound, powerUpSound.length);
             gameObject.GetComponent <SpriteRenderer > ().enabled = false;
             StartCoroutine (SlowMoRoutine (time, speed));
 
         } 
          
     }
 
 }
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
PowerUp timer not working when altering timeScale 0 Answers
Do Slowmotion effect for x seconds 1 Answer
Best way to get code to run at very precise timing? 0 Answers
Slow Motion Issues! 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                