Trying to make dash energy system...
Hello! I am struggling with creating dash energy system.
I have this script for dashing:
 void Start() { StartCoroutine(DashRestoreCoroutine()); }
 IEnumerator DashRestoreCoroutine()
 {
     if (restoreDash < 3)
     {
         restoreDash = restoreDash + 1;
         yield return new WaitForSeconds(3);
     }
 }
On every dash restoreDash decreases by 1 but it doesn't increase every 3 seconds. Can someone help? :c
Answer by Scribe · Mar 21, 2018 at 08:24 PM
You are starting your coroutine once, but it exits after the first time it goes below 3:
 if  restoreDash < 3 then
 add one to restoreDash  immediately
 then wait 3 seconds and end the coroutine.
One way would be to loop the execution so it happens forever:
 while(true /* keep doing this forever, alternatively this could be 'isDashEnabled' or something*/ ) {
     if (restoreDash < 3){ //if we are not at full charge
         restoreDash  ++; //add one to the charge immediately (you may want this to come after the wait on the next line?)
         yield return new WaitForSeconds(3); //then wait 3 seconds before checking again
     }
 
     yield return null; //let other processes progress and then start again
 }
Thank you a lot, I finally have working energy system now c:
Your answer
 
 
             Follow this Question
Related Questions
Trouble with Co routines & WaitForSeconds 0 Answers
Add an value to a variable after 2 seconds 1 Answer
Yield wait for seconds not working at all? 2 Answers
yield ends method 0 Answers
Getting a variable timed Interval with coroutine and yield? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                