- Home /
Boost Script Time problems
So I have a script in my game for a plane. And I want to give it a speed boost, which I have. But I just can't figure out time vairables. soooo here's my script. I'ts apparently wrong, because the update() function can't coroutine. Any Ideas how to fix this?
     //speed variables  
     var speed = 5.0;  
       
     //boost variables  
     var boost = 1.0;  
     var strength = 1.0;  
     var boostLength = 5.0;  
     var boostReload = 10.0;  
     var hasBoost = false;  
     
     function Update () {  
         //Sets Constant speed for Plane * Boost  
         transform.Translate(0, 0, (Time.deltaTime * speed * strength));  
           
     if(Input.GetButtonDown("Boost")) {  
             if (hasBoost==false){  
                 hasBoost = true;  
                 strength +=boost;  
                 //figure out time count down  
                 yield WaitForSeconds(boostLength);  
                 strength -=boost;  
                 yield WaitForSeconds(boostReload);  
                 hasBoost = false;  
             }  
         }  
 }  
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Eli-Davis · May 26, 2011 at 07:18 PM
Nevermind, I figured it out...
 //Boost variables
 var boost = 1.0;
 var strength = 1.0;
 var boostLength = 5.0;
 var boostReloadTime = .5;
 var boostLimit = 5.0;
 var hasBoost = false;
 //BOOOOOSSSSTTTTTTTTTT
     if(Input.GetButtonDown("Boost")) {
         if (hasBoost==false){
             hasBoost = true;
             strength +=boost;
         }
     }
     
     if(hasBoost == true){
         if(boostLength > 0){
             boostLength -= 1 * Time.deltaTime;
         }
         else{
             strength -=boost;
             hasBoost = false;
         }
     }
     //Boost Reload
     if(hasBoost == false){
         if(boostLength < boostLimit){
             boostLength += boostReloadTime *Time.deltaTime;
         }
     }
Your answer
 
 
             Follow this Question
Related Questions
How to increase rate of a falling object in pooling object? 1 Answer
Limited Energy Regeneration 3 Answers
How to delay a function (how to use WaitForSeconds() and yield) 1 Answer
Waitforseconds vs Time 2 Answers
Increase variable for a few seconds 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                