Create a variable decreasing by a value

Hi, im new around here, and new in scripting, i wanted to create a variable like a need water, if the player dont give water to the plant then the plant health decrease, i have made a progress bar decreasing the level of the water but i only want to decrease that bar by 1 in 2 in 2 minutes, my code is here:

Plant.js

var NeedWater : int = 100;

function Update () {
NeedWater -= Clock.minutes / 10 ;
}

Clock.js

#pragma strict
var isTimeRunning = false;
var mainSeconds : int;
public static var seconds : int;
public static var minutes : int;
public static var hours : int;
public static var days : int;
public static var weeks : int;
public static var months : int;
public static var years : int;

function Start () {
isTimeRunning = true;
}

function Update () {
 if(isTimeRunning == true)

        {

            mainSeconds = Time.time;

           

            seconds = mainSeconds  % 60;

            minutes = (mainSeconds / 60) % 60;

            hours   = (mainSeconds / 3600) % 24;

            days    = (mainSeconds / 86400) % 336;

            weeks   = (mainSeconds / 604800) % 48;

            months  = (mainSeconds / 2419200) % 12;

            years   = (mainSeconds / 29030400); 

        }
}

How do i decrease that needwater variable by 1 in 2 in 2 minutes, for example if are 6pm and the bar is 100% at 6:02pm the bar should be 99%, how can i do it? Please help

You would have to get startTime;
timeInSeconds =Time.time - startTime .
In 120 seconds you want to subtract one.
needwater = 100 - timeInSeconds/120;

Thanks a lot!! :slight_smile: