# Help with my hydration script (probably simple)

how do I make this go down -3 curWater every 15 seconds
(Sorry,I don’t know how to do time based stuff yet)

``````public int maxWater = 100;
public int curWater= 100;

public float healthbarLength;

// Use this for initialization
void Start () {
healthbarLength = Screen.width / 2;
}

// Update is called once per frame
void Update () {

}

void OnGUI() {
GUI.Box(new Rect(10, 10, healthbarLength, 20), curWater + "/" + maxWater);
}

if(curWater < 0)
curWater = 0;

if(curWater > maxWater)
curWater = maxWater;
if(maxWater < 1)
maxWater = 1;

healthbarLength = (Screen.width /2) * (curWater / (float)maxWater);
``````

}

}

Make it a float or you can’t simply make it time based. Time.deltaTime, which is used to adjust values to be time based, is a tiny fractional number. It is the time in seconds how long it took to reander the last frame. When you have a frame rate of 100 fps the value is 0.01

When you add this deltaTime each frame to a variable it adds up to exactly 1.0 (since 100 times 0.01 equals 1.0). So using deltaTime will give you a rate of 1/sec. Now you can simply multiply the value with your desired rate. When you multiply deltaTime by 3 it’s 3 times faster so it will reach the value of 3.0 after 1 sec (or the value of 1.0 after 0.33333 sec)

Your clamping can be done more easily with Mathf.Clamp ``````public float maxWater = 100;
public float curWater= 100;

public float healthbarLength;

void Update ()
{
}

void OnGUI()
{
GUI.Box(new Rect(10, 10, healthbarLength, 20), curWater + "/" + maxWater);
}