Question by
lefk36 · Nov 25, 2021 at 03:17 PM ·
timersliderslowmotionenumerate
Slider that reduces value based on timer
I have created a slider that reduces based on the timer of my power up(slowing time for enemies). What I can't seem to be able to do is make the timer go down only when the power up is Active. This is the code for the Enumeration
private IEnumerator slowDownTimer(float duration, Slider slider)
{
// Slows time for enemies
GameManager.enemyTime = 0.1f;
Debug.Log("space key was pressed");
//Timer of three seconds, and reset of enemy speed
yield return new WaitForSeconds(duration);
GameManager.enemyTime = 1f;
// Decreases the Slider value over time
if (slider != null)
{
float timeScale = (slider.value / (duration / 0.5f));
while (slider.value >= 0)
{
slider.value -= timeScale;
yield return new WaitForSeconds(duration);
if (slider.value <= 0)
{
break;
}
}
yield return null;
}
}
Comment
You are using all the time same duration so it waits duration than it goes to next one and hey I allready waited that long so without pausing it goes forward. Use
WaitForSecondsRealtime
Instead
This might help.
Your answer
Follow this Question
Related Questions
How do I decrease a slider over time? 1 Answer
Powerup Timer Help 0 Answers
Do Slowmotion effect for x seconds 1 Answer
how to make knockback and slowmotion when hit by enemy 0 Answers
Need help with making disappearing platforms. Error CS1525 1 Answer