Powerup Timer Help
I am trying to create a powerup that slows down the game time. I can get the desired effect to work, but the game never goes back to the original timescale. The timer is not working. I tried using duration=time*speed to compensate for the timescale alteration, but this is not working. I have been looking into Time.unscaledTime, but don't know to incorporate it into my code. I have tried many different codes and continue to run into the same issue! I tried setting the time variable to 5 and speed to .5 so the effect should stop after 2.5 seconds slowmo speed, but no luck. This is one of the last obstacles I need to overcome in order to complete my game.
Code:
using UnityEngine;
using System.Collections;
public class PWRUP : MonoBehaviour {
public float time;
public float speed;
IEnumerator SlowMoRoutine(float time, float speed)
{
float duration = time * speed;
Time.timeScale = speed;
yield return new WaitForSeconds (duration);
Time.timeScale = 1f;
}
void OnTriggerEnter2D(Collider2D other){
if (other.tag == "Player") {
StartCoroutine (SlowMoRoutine (time, speed));
}
gameObject.SetActive (false);
Destroy(gameObject);
}
}
Your answer
Follow this Question
Related Questions
Slow Motion PowerUp 0 Answers
PowerUp Tutorials 1 Answer
Do Slowmotion effect for x seconds 1 Answer
Slider that reduces value based on timer 0 Answers
timer stopwatch 2 Answers