Adding a value to a variable every second

I have spent a while trying to figure this out and promised my last resort would be Unity Answers. But here I am.

I need to increase a variable by 1 every second. I’ve tried to do:

thirst += Time.deltaTime * 1;

but it just doesn’t seem to work.

Time.deltaTime gives you the time since the last frame. Computing thirst += Time.deltaTime; will increase the thirst counter by the length of a frame, every frame – hence, one unit per second.

If you are not seeing this behavior, chances are you are resetting thirst somewhere, or you have done something to the Time scale. In other words, your code should work, unless there are bits of it you’re not telling us about.

Try adding a log statement whenever you increment thirst, and see how the values evolve.

int gameStartTime=(int)Time.time

void update(){
if((int)Time.time-gameStartTime==1){
//do something here
gameStartTime=(int)Time.time
}
}

There are quite a few ways.
The first one, using while loop

var value : Boolean = true;

function AddSomeValue(){ //call this when you need to start adding
     while(value){ //this lets you stop the loop at any time
          //just change the value of this variable to false
          yield WaitForSeconds(1);
          thirst++;
     }
}

Another, using invokerepeating

InvokeRepeating("AddValue", 1, 1); // function string, start after float, repeat rate float

function AddValue () {
	thirst++;
}

you can cancel invokerepeating using CancelInvoke(), but if you have many of them in one script, it will stop all of them

Time.deltaTime is the amount of time it takes to load the last frame, so for example 0.2 seconds. Therefore, what you said above would be seen to the computer like this:
thirst += 0.2 * 1;
multiplying that number by one, doesnt change it in the first place anyways; so its normal it doesnt work.