# Decreasing bar

**URL:** https://discussions.unity.com/t/decreasing-bar/70084
**Category:** Questions & Answers
**Created:** [May 4, 2013, 2:32am UTC](https://discussions.unity.com/t/decreasing-bar/70084 "2013-05-04T02:32:41Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![androids](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@androids](https://discussions.unity.com/u/androids)
#### Post date: [May 4, 2013, 2:32am UTC](https://discussions.unity.com/t/decreasing-bar/70084/1 "2013-05-04T02:32:41Z")

</div>

I tried to make a bar that desreases automatically with a current time from 100% to 0%. The bar can increase with 50% if the player takes an object. And if the bar is 0%, you have to go to alternative scene. Someone who can help me out with. I’m really confused now. I’m working with JS.

Thanks in advance.

---

<div class="post-metadata">

### Author: ![robertbu](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@robertbu](https://discussions.unity.com/u/robertbu)
#### Post date: [May 4, 2013, 3:03am UTC](https://discussions.unity.com/t/decreasing-bar/70084/2 "2013-05-04T03:03:46Z")

</div>

All you need to to add a timer:

```
#pragma strict

var totalTime = 5.0;
var remainingTime = 5.0;
var Bar:Texture2D;
var BarWidth:float=400;
var BarHeight:float=200;

function Update() {
	if (remainingTime > 0.0)
		remainingTime -= Time.deltaTime;
}
 
function OnGUI(){
    GUI.DrawTexture(Rect( (Screen.width - BarWidth)*0.5,(Screen.height - BarHeight)*0.5, BarWidth* remainingTime/totalTime, BarHeight), Bar);
}

```
