How can I decrease points by the second?

In my game, I have coded a variable,

public float points;

, that I would like to be decreased from 1000 for every second since the game starts. The game will start with the points at 1000, and decrease endlessly until the player reaches the end of the game. How can I do this?

You would have to use Time.time (the current time) to determine when a second has passed.

When a second has passed just do points -= 1;

I’d provide an example but I only know UnityScript so hopefully it helps.

var timeSecond : float = 1; //variable in which it is the Time.time variable plus 1
var points : float = 1000;

function Update () {

if (Time.time >= timeSecond){ //if the current time is greater than or equal to the one second mark
points -= 1; //set points to current value - 1
timeSecond += 1; //set 1 second past time to current value + 1
}

}

This should loop and work, I haven’t tested it though and it’s not in C#.

Hope i helped

As you have written it the game would be over in one second. Regardless, something like

Start() {
// setup stuff

StartCoroutine(decreaseScore());
}

IEnumerator decreaseScore() {
while (score > 1) {
score = score - 1000;
yield return new WaitForSeconds(1);
}

// call GameOver

}

Edit: replace ‘score’ with ‘points’, just noticed you were using that variable name