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 () {
AddjustCurrentWater(0);
}
void OnGUI() {
GUI.Box(new Rect(10, 10, healthbarLength, 20), curWater + "/" + maxWater);
}
public void AddjustCurrentWater(int adj) {
curWater += adj;
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 ()
{
AddjustCurrentWater(Time.deltaTime * 3.0f);
}
void OnGUI()
{
GUI.Box(new Rect(10, 10, healthbarLength, 20), curWater + "/" + maxWater);
}
public void AdjustCurrentWater(float adj)
{
curWater += adj;
maxWater = Mathf.Max(maxWater, 1.0f)
curWater = Mathf.Clamp(curWater, 0.0f, maxWater);
healthbarLength = (Screen.width / 2.0f) * (curWater / maxWater);
}
Btw: It’s usually much easier to work with values between 0.0f and 1.0f. You can multiply the value by your “imaginary” max value when you want to display the value to the user.
Also don’t forget that you can cast the float into an int value when you display it.