Timer doesnt count back up!

Hey guys,

I’ve got a problem with my timer. Basically i want it to count back up after it has counted down to 0.
I know im probably missing another function or something, but i cant seem to figure this out.

Here is my code:

var timer : float = 5;

function Start ()
{
	renderer.material.color.a = 1;
	Screen.showCursor = false;
	Screen.lockCursor = true;
}
	
function Update (){

	timer = timer - Time.deltaTime;
	if(timer >= 0)
	{
		renderer.material.color.a -= 0.15 * Time.deltaTime;
	}
	
	if(timer <= 0)
	{
		timer = 0;
	}
}
	timer = timer + Time.deltaTime;
	if(timer >= 5)
	{
		renderer.material.color.a += 0.15 * Time.deltaTime;
	}
	
	if(timer >= 5)
	{
		timer = 5;
}	

Thanks
Smoke

You substract Time.deltaTime and you add it to you timer so it’ll never actually move, you 've got to define the two states with a bool for example like :

`

var timer : float = 5;
var rising : boolean = false; // New Variable false : timer should go down, true timer should go up

function Start ()
{
 renderer.material.color.a = 1;
 Screen.showCursor = false;
 Screen.lockCursor = true;
  }
 
function Update (){
  if(!rising)
  {
    timer = timer - Time.deltaTime;
    if(timer >= 0)
    {
        renderer.material.color.a -= 0.15 * Time.deltaTime;
    }
 
    if(timer <= 0)
    {
        timer = 0;
    }
    if(timer == 0) // If timer == 0 you should now go up
         rising = !rising;
 }
 else
 {
     timer = timer + Time.deltaTime;
     if(timer >= 5)
    {
        renderer.material.color.a += 0.15 * Time.deltaTime;
    }
 
     if(timer >= 5)
    {
        timer = 5;
    }
  }
}

`

Hope it helps you understand your problem.

Thanks man, that worked.
I knew i was missing a variable but wasnt sure exactly where i screwed up.

+Rep