I’m trying to make a script where the players score increases by 100 every 10 seconds. I’ve been searching around on the forums and other places but I just can’t find a good way to do this. Please help me.
Use InvokeRepeating.
–Eric
function Start() {
InvokeRepeating("AddScore", 10, 10); // Starting in 10 seconds, call method every 10 seconds.
}
function AddScore() {
Score += 100;
}
You should be able to work off of that.
Thank you so much. That helped a lot. But now I get a wierd problem. I altered the code to:
static var playerScore = 0;
function Start() {
InvokeRepeating("AddScore", 10, 10); // Starting in 10 seconds, call method every 10 seconds.
}
function AddScore() {
playerScore += 100;
GameObject.Find("t_scorePrefab").guiText.text = ""+playerScore;
}
When the timer reaches 10 and the score is supposed to added. The game pauses and I get an error