Increase bar based upon time

I’m trying to create a bar which increases based upon time. So for example I might want it to be completely filled within 1 second of 1/2 a second etc.

Right now I’m just filling it up every Update(), by increasing it’s value by 1, but I’m not sure how to tie all of it together with using actual time.

Here’s my code so far

void UpdateMachines()
	{

		for (int i = 0; i<productsArray.Count; i++) {			
			
			ProductData product = productsArray*;*
  •  	if(product.makeStuff == true)*
    
  •  	{*
    
  •  		ProductTemplateData productTemplate = product.data;*
    
  •  		//product.currentTime --;*
    
  •  		//if(product.currentTime <0)*
    
  •  		//{*
    
  •  			Debug.Log (product.amount);*
    
  •  			product.currentTime = productTemplate.constructionTime;*
    
  •  			product.barAmount ++;*
    
  •  			if(product.barAmount >= 100)*
    
  •  			{*
    
  •  				product.barAmount = 0;*
    

_ IncreaseMoney(product.amount*productTemplate.costToSell);_

  •  				if(product.autoMakeStuff == false)*
    
  •  				{*
    
  •  					product.makeStuff = false;*
    
  •  				}*
    
  •  			}*
    
  •  			UpdateProductConstructionTime(product.bar, product.barAmount);*
    
  •  		//}*
    
  •  	}*
    
  •  }*
    
  • }*

Try [Mathf.Lerp][1]. Maybe something like this:

float lengthOfLerp = 5f;   // Duration of the lerp, example: 5 seconds
float[] productLerpTimes;        // each product will fill up based on a lerp time (0 to 1)
void Start() {
     productLerpTimes = new float[productsArray.Count];
}

void UpdateMachines()
{
	for (int i = 0; i<productsArray.Count; i++) {            
		ProductData product = productsArray*;*
  •  if(product.makeStuff == true) {*
    
  •  	ProductTemplateData productTemplate = product.data;*
    
  •  	product.currentTime = productTemplate.constructionTime;*
    
  •  	//product.barAmount++;*
    
  •  	if (product.barAmount == 0f) {*
    

_ productLerpTimes = 0f;_
* }*
_ productLerpTimes += Time.deltaTime / lengthOfLerp;
product.barAmount = Mathf.Lerp(0f, 100f, productLerpTimes*);*_

* if(product.barAmount >= 100)*
* {*
//…
_*[1]: http://docs.unity3d.com/ScriptReference/Mathf.Lerp.html*_